0

レイアウトxmlのヘルプが必要です。テキストビューの高さ(textview.getHeightを使用)と画面の高さ(DisplayMetrics.getMetrics()を使用)のコードで以下のxmlレイアウトの以下のディメンションをテストすると、78.9%になります。つまり、テキストビューの高さは次のようになります。画面の高さの78.9%。テキストビューと他のコンポーネント(ボタン)を持つ2つの相対レイアウトにそれぞれ重み1と9を割り当てたので、これは90%になると予想していました。誰か助けてくれませんか。私の目的は、テキストビューを画面の高さの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"/>

4

1 に答える 1

2

それぞれの高さRelativeLayoutをゼロに設定すると、「スペア」スペース(すべて100%)が重みに応じて割り当てられます。ゼロ以外のサイズから始める場合、重みは、ウィジェットのサイズが通常のサイズに割り当てられた後でのみ、ウィジェットのサイズを調整するために使用されます。

于 2013-01-08T23:07:33.233 に答える