【发布时间】:2013-07-23 18:27:02
【问题描述】:
无论屏幕尺寸或 DPI 是多少,我怎样才能使某些布局成为屏幕宽度的 80% 或 90%?我尝试使用 " 但我得到了 80% 的高度。
编辑:
<?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"
android:background="@drawable/background" >
<Button
android:id="@+id/bNivoi1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="80dp"
android:background="@drawable/button_nivoi_back" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvOpis15Nivoa"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="15sp"
android:layout_weight="0.8"
android:text="text" />
</LinearLayout>
</LinearLayout>
我只需要 textview 占屏幕的 80%,而不是活动的其余部分。
【问题讨论】:
-
按照@ianhanniballake 的回答,将现有布局包装在水平方向的LinearLayout 中(您无需明确指定,默认为水平),然后使用
android:layout_weight="0.8"。 -
不知何故它不起作用。让我编辑我的帖子并粘贴我的 XML。