标签:android style io color ar sp 文件 on art
从一个页面返回到另一个页面,两种方法:
第一种也是我最常用的一种:
<LinearLayout
                android:id="@+id/linearLayout"
                android:layout_width="fill_parent"
                android:layout_height="45dp"
                android:background="@color/tomato1"
                android:orientation="horizontal" >
                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.0" >
                    <ImageView
                        android:id="@+id/back"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/back_bu_bg_selector" />
                </LinearLayout>
                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0" >
                    <TextView
                        android:id="@+id/title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:text="关于软件"
                        android:textColor="#ffffff"
                        android:textSize="18sp" />
                </RelativeLayout>
                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="2.0"
                    android:padding="5dp" >
                </LinearLayout>
            </LinearLayout>
在Activity中声明变量
private ImageView back = null ;
在onCreate方法中
back= (ImageView) findViewById(R.id.back);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
在布局文件左上角写一个ImageView
第二种,是今天新学习的一种:
是一个RelativeLayout布局里嵌套一个LinearLayout布局
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#FA8300"
        android:padding="10dp" >
        <LinearLayout
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:onClick="goBack"
            android:orientation="horizontal"
            android:visibility="gone" >
            <ImageView
                android:layout_width="23dp"
                android:layout_height="match_parent"
                android:padding="5dp"
                android:scaleType="fitXY"
                android:src="@drawable/icon_back" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="返回"
                android:textColor="@color/white"
                android:textSize="16sp" />
        </LinearLayout>
        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="选择您的管家,享受宅生活"
            android:textColor="@color/white"
            android:textSize="16sp" />
    </RelativeLayout>
在Activity中声明变量
private LinearLayout ll_back;
在onCreate方法中
ll_back = (LinearLayout) findViewById(R.id.back);
在下面写一个goBack方法返回上个页面
public void goBack(View v)
    {
startActivity(new Intent(this, HomePageActivity.class));
finish();
    }
标签:android style io color ar sp 文件 on art
原文地址:http://blog.csdn.net/u011742151/article/details/40988245