無論屏幕尺寸或DPI是多少,我怎樣才能使一些佈局成爲例如屏幕寬度的80%或90%?我試着用「,但我得到了高度則有80%如何使佈局成爲屏幕寬度的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」'。 – Vikram
不知何故,它不工作。讓我編輯我的帖子並粘貼我的XML。 – marjanbaz