1. 程式人生 > >Android 自適應的一種佈局,weight

Android 自適應的一種佈局,weight

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.testlayout.MainActivity" >


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


        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#ff0000"
            android:text="@string/hello_world" />


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >


            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ff0000"
                android:text="@string/hello_world" />


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >


                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="100dp"
                    android:background="#00ff00"
                    android:text="你好啊,阿斯蒂芬" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/rl_product_reduce"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="17dp"
        android:layout_marginRight="17dp"
        android:layout_marginTop="200dp"
        android:orientation="horizontal" >


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >


            <ImageView
                android:id="@+id/iv_reduce"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_minus"
                android:scaleType="fitStart" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:orientation="horizontal" >


            <EditText
                android:id="@+id/et_yield"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="36dp"
                android:background="@drawable/shap_bg_rectangle"
                android:gravity="center"
                android:inputType="number"
                android:text="5000"
                android:textColor="#939393"
                android:textSize="15sp" />


            <ImageView
                android:id="@+id/iv_add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_add"
                android:scaleType="fitCenter" />
        </LinearLayout>
    </LinearLayout>


</RelativeLayout>