android中典型的LinearLayout

    xiaoxiao2021-04-19  163

    1的实现:给中间组件设置权重android:layout_weight="1"

    2的实现:给每个组件设置权重为1和高度为“fill_parent”或“match_parent-à

    android:layout_height="match_parent"

            android:layout_weight="1"

    3带有背景图片的文本框的实现:

    这两个文本框实则是两个LinearLayout,里面分别内嵌了<TextView>,<EditText>,<ImageButton>

    1LinearLayout给它的背景设置为:android:background="@android:drawable/edit_text"

    2EditText的背景何权重设置为:

    android:layout_weight="1" android:background="@null"

    3ImageButton的样式和图片设置为:style="@android:style/Widget.Button.Inset"

    android:src="@android:drawable/star_big_on"

      具体实现代码如下所示:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical" >

     

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:addStatesFromChildren="true"

            android:background="@android:drawable/edit_text"

            android:gravity="center_vertical"

            android:paddingRight="0dip" >

     

            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="From:"

                android:textAppearance="?android:attr/textAppearanceLargeInverse"

                android:textColor="?android:attr/textColorSecondary" />

     

            <EditText

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_weight="1"

                android:background="@null"

                android:singleLine="true" />

     

            <ImageButton

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginBottom="2dip"

                android:layout_marginRight="2dip"

                android:layout_marginTop="2dip"

                android:padding="10dip"

                style="@android:style/Widget.Button.Inset"

                android:src="@android:drawable/star_big_on" />

        </LinearLayout>

     

        <LinearLayout

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:addStatesFromChildren="true"

            android:background="@android:drawable/edit_text"

            android:gravity="center_vertical"

            android:orientation="horizontal"

            android:paddingRight="0dip" >

     

            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="To:"

                android:textAppearance="?android:attr/textAppearanceLargeInverse"

                android:textColor="?android:attr/textColorSecondary" />

     

            <EditText

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_weight="1"

                android:background="@null"

                android:singleLine="true" />

     

            <ImageView

                style="@android:style/Widget.Button.Inset"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginBottom="2dip"

                android:layout_marginRight="2dip"

                android:layout_marginTop="2dip"

                android:padding="10dip"

                android:src="@android:drawable/star_big_on" />

        </LinearLayout>

     

    </LinearLayout>

    转载请注明原文地址: https://ju.6miu.com/read-676004.html

    最新回复(0)