在LinearLayout中,使用
android:layout_weight="1"
android:layout_height="0dp"
这种写法是否可以将控件的高度设置为余下的所有空间?
为什么这段代码用在ListView和RecyclerView可以完美占据剩余空间,而在TextView中却不可以呢?
求教!
代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="1">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/pider"
android:background="@color/pide" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/app_notify_content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/app_alert_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/common_item_padding"
android:layout_marginEnd="@dimen/common_item_padding"
android:layout_marginTop="26dp"
android:layout_marginBottom="7.3dp"
android:text="@string/app_notify_tips"
android:textColor="@color/black40"
android:textSize="11.3sp" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/pider"
android:layout_marginLeft="@dimen/common_item_padding"
android:layout_marginRight="@dimen/common_item_padding"
android:background="@color/pide" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="51dp">
<TextView
android:id="@+id/app_switch_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15.3dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23.3dp"
android:text="@string/enable_app_alert"
android:textColor="@color/black70"
android:textSize="14.7sp" />
<Switch
android:id="@+id/app_notification_alert_switch"
android:layout_width="40dp"
android:layout_height="21dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="23.3dp"
android:visibility="visible"
style="@style/switchStyle"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/pider"
android:layout_marginLeft="@dimen/common_item_padding"
android:layout_marginRight="@dimen/common_item_padding"
android:background="@color/pide" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="51dp">
<TextView
android:id="@+id/app_notifi_awake_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15.3dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="23.3dp"
android:text="仅在熄屏时通知"
android:textColor="@color/black70"
android:textSize="14.7sp" />
<Switch
android:id="@+id/app_notifi_awake_switch"
android:layout_width="40dp"
android:layout_height="21dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="23.3dp"
style="@style/switchStyle" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/pider"
android:layout_marginLeft="@dimen/common_item_padding"
android:layout_marginRight="@dimen/common_item_padding"
android:background="@color/pide" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/common_item_padding"
android:layout_marginTop="26dp"
android:gravity="center_vertical"
android:text="@string/selected_alert_apps"
android:textColor="@color/black40"
android:textSize="11.3sp" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/pider"
android:layout_marginLeft="@dimen/common_item_padding"
android:layout_marginRight="@dimen/common_item_padding"
android:layout_marginTop="7.3dp"
android:background="@color/pide" />
<TextView
android:id="@+id/list_tip"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginTop="-15dp"
android:text="afasdfsdvsdfbsdfgbsdfhsghnsdfgsdfgasdgasdfgshnsgh"
android:textSize="14.7sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/chart_bottom_bar_height"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/pider"
android:background="@color/pide" />
<TextView
android:id="@+id/add_notification_app_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="4.7dp"
android:gravity="center"
android:drawableTop="@drawable/app_notify_edit_button_press"
android:layout_marginTop="2dp"
android:text="@string/edit_app"
android:textColor="@color/black40"
android:textSize="9.3sp" />
</FrameLayout>
</LinearLayout>
<View
android:id="@+id/mask_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:clickable="true"
android:background="#77f7f7f7"
android:visibility="gone"/>
</FrameLayout>
</LinearLayout>
<View
android:id="@+id/mask_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:clickable="true"
android:background="#77f7f7f7"
android:visibility="gone"/>
</FrameLayout>
</LinearLayout>
Ia juga boleh dilakukan dalam paparan teks Adakah fon paparan teks anda terlalu kecil dan ia dipaparkan di bahagian atas?
Siarkan keseluruhan fail reka letak paparan teks anda
Siarkan semua fail reka letak anda
LinearLayout mempunyai arah,
Ia hanya menduduki ruang yang tinggal dalam reka letak menegak Jika LinearLayout mendatar, ia tidak akan berkuat kuasa
Dengan cara ini