当前位置: 编程技术>移动开发
本页文章导读:
▪仿it快播顶部button点击背景滑动切换的成效 仿it快播顶部button点击背景滑动切换的效果
最近在it快播中看见它顶部的几个button可以点击后 背景会滑动到相应的button后面 就得很好看 就想办法实现了那效果
思路 大概就是通过view的叠加 .........
▪ google技艺 google技巧
inurl:javasite:intitle:长字符串精确查找用 ""不希望出现某词 -
......
▪ 怎么禁止Gridview下上滑动 如何禁止Gridview上下滑动
因为android没有提供直接禁止Gridview滑动的API,也没有提供相应的属性来在XML布局文件中直接禁止滑动,当我们做菜单时要禁止Gridview上下滑动怎么办呢?1、自定义.........
[1]仿it快播顶部button点击背景滑动切换的成效
来源: 互联网 发布时间: 2014-02-18
仿it快播顶部button点击背景滑动切换的效果
最近在it快播中看见它顶部的几个button可以点击后 背景会滑动到相应的button后面 就得很好看 就想办法实现了那效果
思路 大概就是通过view的叠加 把3个button通过RelativeLayout布局置于一个imageView的上面一层 然后控制imageView移动来实现效果 效果如下:
下面是我的代码 可能有点二 大家见谅!
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="@drawable/top_channel_bg_normal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/bg_img"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="/blog_article/@drawable/top_channel_bg_selected/index.html" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<Button
android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.33"
android:background="#00000000"
android:text="button_1"
android:textColor="#ffffff" />
<Button
android:id="@+id/button_2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.33"
android:background="#00000000"
android:text="button_2"
android:textColor="#ffffff" />
<Button
android:id="@+id/button_3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.33"
android:background="#00000000"
android:text="button_3"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
接着是activity的代码
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class TestBackGroundMoveAppActivity extends Activity implements
OnClickListener {
/** Called when the activity is first created. */
private ImageView bgImage;
public final static String MYTAG = "msg";
private Button button_1;
private Button button_2;
private Button button_3;
private int selected_button_position = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
private void init() {
setContentView(R.layout.main);
bgImage = (ImageView) findViewById(R.id.bg_img);
button_1 = (Button) findViewById(R.id.button_1);
button_2 = (Button) findViewById(R.id.button_2);
button_3 = (Button) findViewById(R.id.button_3);
LayoutParams p = bgImage.getLayoutParams();
float screen_w = getWindowManager().getDefaultDisplay().getWidth();
screen_w = screen_w / 3;
p.width = (int) screen_w;
bgImage.setLayoutParams(p);
button_1.setOnClickListener(this);
button_2.setOnClickListener(this);
button_3.setOnClickListener(this);
}
private void setSelectButtonBgByPosition() {
int w = getWindowManager().getDefaultDisplay().getWidth() ;//3是button的个数
int l = (int)(w / 3.0) * selected_button_position;
int r = l + bgImage.getWidth();
if(selected_button_position == 0) {//选择第一个button
l = 0;
r =(int)(w / 3.0);
}else if(selected_button_position == 2){//选择最后一个button
r = w;
}
int t = bgImage.getTop();
int b = bgImage.getBottom();
bgImage.layout(l, t, r, b);
bgImage.invalidate();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int select = 0;
if (v == button_1) {
select = 0;
} else if (v == button_2) {
select = 1;
} else if (v == button_3) {
select = 2;
}
int w = bgImage.getWidth();
TranslateAnimation animation = null;
int startX = w * selected_button_position;
Log.d(MYTAG, "" + startX);
int endX = w * (select - selected_button_position);
Log.d(MYTAG, "" + endX);
animation = new TranslateAnimation(0, endX, bgImage.getTop(),
bgImage.getTop());
selected_button_position = select;
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
setSelectButtonBgByPosition();
bgImage.clearAnimation();
}
});
animation.setDuration(1 * 1000);
bgImage.startAnimation(animation);
}
}
其实就通过TranslateAnimation 实现移动的效果 修改位置呢 则是通过View自带的layout(int l,int t,int r,int b)的这个函数 很简单的 :-)
附上用的素材(就是解压it快播除出来的!) 最后的两张图
最后附上源码!
[2] google技艺
来源: 互联网 发布时间: 2014-02-18
google技巧
inurl:java
site:
intitle:
长字符串精确查找用 ""
不希望出现某词 -
inurl:java
site:
intitle:
长字符串精确查找用 ""
不希望出现某词 -
[3] 怎么禁止Gridview下上滑动
来源: 互联网 发布时间: 2014-02-18
如何禁止Gridview上下滑动
因为android没有提供直接禁止Gridview滑动的API,也没有提供相应的属性来在XML布局文件中直接禁止滑动,当我们做菜单时要禁止Gridview上下滑动怎么办呢?
1、自定义一个Gridview
2、通过重新dispatchTouchEvent方法来禁止滑动
public class GrapeGridview extends GridView {
public GrapeGridview(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public GrapeGridview(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public GrapeGridview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
//通过重新dispatchTouchEvent方法来禁止滑动
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if(ev.getAction() == MotionEvent.ACTION_MOVE){
return true;//禁止Gridview进行滑动
}
return super.dispatchTouchEvent(ev);
}
}
3、在xml布局中引用时记得写上自己的定义的gridview全路径名称
如:
<com.wjq.menu.GrapeGridview android:id="@+id/gridview"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:numColumns="4" android:verticalSpacing="10dip"
android:horizontalSpacing="10dip" android:stretchMode="columnWidth"
android:gravity="center" />
本人欢迎转载:但是请注明原文地址:http://blog.sina.com.cn/s/blog_4a4f9fb50100tyfk.html
谢谢
因为android没有提供直接禁止Gridview滑动的API,也没有提供相应的属性来在XML布局文件中直接禁止滑动,当我们做菜单时要禁止Gridview上下滑动怎么办呢?
1、自定义一个Gridview
2、通过重新dispatchTouchEvent方法来禁止滑动
public class GrapeGridview extends GridView {
public GrapeGridview(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public GrapeGridview(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public GrapeGridview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
//通过重新dispatchTouchEvent方法来禁止滑动
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if(ev.getAction() == MotionEvent.ACTION_MOVE){
return true;//禁止Gridview进行滑动
}
return super.dispatchTouchEvent(ev);
}
}
3、在xml布局中引用时记得写上自己的定义的gridview全路径名称
如:
<com.wjq.menu.GrapeGridview android:id="@+id/gridview"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:numColumns="4" android:verticalSpacing="10dip"
android:horizontalSpacing="10dip" android:stretchMode="columnWidth"
android:gravity="center" />
本人欢迎转载:但是请注明原文地址:http://blog.sina.com.cn/s/blog_4a4f9fb50100tyfk.html
谢谢
最新技术文章: