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

来源:互联网 发布:男人眼中的女人味知乎 编辑:程序博客网 时间:2024/04/30 16:57

1. GridView  关键点还是在于adapter的实现

GridViewActivity.java 

public class GridViewActivity extends Activity {private int[] images;private GridView gridView;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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{@Overridepublic int getCount() {// TODO Auto-generated method stubreturn images.length;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn images[position];}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic 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>



0 0
原创粉丝点击