需要布局xml的帮助。当我在我的代码中测试下面的xml布局的尺寸时,文本视图的高度(通过使用textview.getHeight)与屏幕的高度(通过DisplayMetrics.getMetrics()),它为78.9%,这意味着textview的高度是屏幕高度的78.9%。我期待这应该是90%,因为我已经将权重1和9分配给我的两个相对布局,它们分别具有textview和其他组件(按钮)。谁能请帮忙。我的目标是使textview成为屏幕高度的10%。
<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"/>
答案 0 :(得分:2)
将每个RelativeLayout
的高度设置为零,并根据权重分配“备用”空间(全部100%)。如果您从非零尺寸开始,则权重仅用于在指定正常尺寸后调整窗口小部件大小。