2

シンプルな線形レイアウトで listView のサイズを設定する必要があります。私は最愛の例のように重みを設定しましたが、何かがうまくいかなかった: textView が設定されていないようで、リストはより大きな次元を取ります。

<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"
    android:weightSum="1" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:gravity="center"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="0dp" 
        android:layout_weight="0.7">
    </ListView>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="0.1"
        android:text="Avanti" />

</LinearLayout>

最終的なエラーを修正するにはどうすればよいですか?

これは私が持っているものです:

4

2 に答える 2

0

考えられることの 1 つは、textview の高さを設定することです (たとえば、通常は textSize を設定してから、高さを textsize*3.7 に設定します)。

例えば:

   <TextView
            android:id="@+id/lexplicacionsNumPagText"
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:layout_gravity="right"
            android:gravity="right"
            android:layout_weight="2.10"
            android:scrollHorizontally="false"
            android:singleLine="true"
            android:text="01/05"
            android:textColor="#5d8a3b"
            android:textSize="10.5dip"
            android:textStyle="bold" />

これが役に立たない場合...解決策はプログラムで高さを設定することかもしれません..おそらくそれは最善の方法ではありませんが、多くの問題の後、何度も私の命を救ってくれました。

「onCreate」の最後に追加

    findViewById(R.id.explicacionsLiLa).post(new Runnable(){  //id of your FIRST linearLayout
        public void run(){
            inicialitzarLayout();

        }
    });

これにより、レイアウトが膨張したら、リストビューのサイズを変更するメソッドに移動します。たとえば、高さの 80%

private void inicialitzarLayour(){
     LinearLayout lilaheight  = findViewById(R.id.explicacionsLiLa).getHeight();

     findViewById(R.id.listview1).getLayoutParams().height = (int)(lilaheight*0.8);

}

PS。投稿内に明示的に記述しないと、最後の/前の/..編集で何を変更したかを人々は知りません

于 2012-11-12T15:26:40.707 に答える
0

layout_weightButton や TextView で使用するのは良い考えではないと思います。さて、あなたがそれをどのように見せたいのかよくわかりませんが、私がそれをどのようにやったかは次のとおりです。

<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"
    android:weightSum="1" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </ListView>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Avanti" />
</LinearLayout>

ここで変更する主な値layout_weightは ListView の とweightSumLinearLayout の ですが、Button と TextView が配置された後、ビューの残りの部分を埋めるように思えます。上記の結果に満足できない場合は、layout_weight と weightSum を試してみてください。

于 2012-11-12T14:36:20.963 に答える