Android 正确设置布局权重
需要关于布局xml的帮助。当我在我的代码中测试以下xml布局的以下维度,测试textview的高度(通过使用textview.getHeight)与屏幕高度(通过DisplayMetrics.getMetrics())时,它的值为78.9%,这意味着textview的高度是屏幕高度的78.9%。我希望这应该是90%,因为我已经为我的两个relativelayouts分配了权重1和9,这两个relativelayouts分别有textview和其他组件(按钮)。谁能帮忙吗。我的目标是让textview占屏幕高度的10%Android 正确设置布局权重,android,Android,需要关于布局xml的帮助。当我在我的代码中测试以下xml布局的以下维度,测试textview的高度(通过使用textview.getHeight)与屏幕高度(通过DisplayMetrics.getMetrics())时,它的值为78.9%,这意味着textview的高度是屏幕高度的78.9%。我希望这应该是90%,因为我已经为我的两个relativelayouts分配了权重1和9,这两个relativelayouts分别有textview和其他组件(按钮)。谁能帮忙吗。我的目标是让textvi
<LinearLayout 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:orientation="vertical"
tools:context=".Story1Activity" >
<RelativeLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textViewStory1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:lineSpacingMultiplier="1.2" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="9"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/buttonPrevious"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:background="@android:drawable/btn_default"
android:text="@string/stringButtonPrevious"
android:onClick="loadPrevious" />
<Button
android:id="@+id/buttonNext"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="@android:drawable/btn_default"
android:text="@string/stringButtonNext"
android:onClick="loadNext"/>
将每个
RelativeLayout
的高度设置为零,将根据权重分配“空闲”空间(全部100%)。如果从非零大小开始,权重仅用于在分配正常大小后调整小部件大小。这很有帮助,谢谢。将高度设置为0将使组件与我想要的比例相同。但是,textview和按钮的总高度仍然与屏幕高度不匹配。我猜原因是上面还有一个标题会占用一些空间。我正在弄清楚如何设置/获得这个高度,这样所有的数字就可以和屏幕高度相加。