您的位置:首页 > 产品设计 > UI/UE

Android UI, GridView, ScrollView, SlidingDrawer 抽屉滑动效果

2014-11-14 16:28 441 查看
1. GridView 关键点还是在于adapter的实现

GridViewActivity.java

public class GridViewActivity extends Activity {

private int[] images;
private GridView gridView;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_gridview);

gridView = (GridView) findViewById(R.id.gridView1);
images = new int[]{
R.drawable.sample_0,
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7
};
MyImageAdapter adapter = new MyImageAdapter();
gridView.setAdapter(adapter);

}

class MyImageAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return images.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return images[position];
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv = new ImageView(GridViewActivity.this);
iv.setImageResource(images[position]);
return iv;
}

}

}
layout_gridview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
android:horizontalSpacing="6dp"
android:verticalSpacing="6dp" >
</GridView>

</LinearLayout>


2. ScrollView 是一个framelayout, 下面只能有一个控件, 一般为linearlayout

可以通过 android:scrollbarThumbVertical 来设置 滚动条的图形

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarThumbVertical="@drawable/ic_launcher" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content"/>

</LinearLayout>

</ScrollView>


3. SlidingDrawer 抽屉滑动效果



可以设置水平垂直方向, 可以根据需求自定义 content

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="@+id/content"
android:handle="@+id/handle"
android:orientation="horizontal"
>

<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle"
android:background="@drawable/button1" />

<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_0" />

</LinearLayout>
</SlidingDrawer>

</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: