0

私は最近、学校向けのアプリに取り組んでおり、公開する前に少しクリーンアップしたいと考えていました。アプリのスケジューリング部分には、同時に画面上にある ListView でアクションを実行する 5 つのボタンがあります。ただし、リストビューが画面を引き継いでボタンを画面から押し出すと、画面に約6つ以上のイベントがある場合に問題が発生し、イベントを削除したり、新しいイベントを作成したりできなくなります。の上。

リストビューを通常の画面の向きで機能する静的サイズ (400px) に設定しようとしましたが、電話が横向きに設定されている場合、ボタンも表示されません。私の現在のコードでは、XML ビューアで動作するように見えますが、実際にはそうではありません。

これは、静的サイズ設定のないコードです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#551A8B"
    android:textColor="#FFD700"
    >



    <Button android:text="@string/New" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/button3">
    </Button>

    <Button android:text="@string/Edit" 
    android:id="@+id/button4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/button3"
    android:layout_alignTop="@id/button3">
    </Button>

    <Button android:text="@string/delete" 
    android:id="@+id/button5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/button4"
    android:layout_alignTop="@id/button4">
    </Button>

        <Button android:layout_height="wrap_content" 
    android:id="@+id/button7" 
    android:layout_width="wrap_content" 
    android:text="@string/Previousweek"
    android:layout_below="@id/button3">
    </Button>

    <Button android:layout_height="wrap_content" 
    android:id="@+id/button6" 
    android:layout_width="wrap_content" 
    android:text="@string/Next"
    android:layout_below = "@id/button3"
    android:layout_toRightOf = "@id/button7">
    </Button>

    <ListView android:id="@+id/listView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"  
    android:textColor="#FFD700"
    android:layout_below="@id/button7" 
    android:textSize="10sp" >
    </ListView> 


</RelativeLayout>

このコードの XML ビューアは次のとおりです。

それはそれがうまくいくと私に信じさせるでしょう。エミュレーターでテストしたところ、ばかげたイベントをたくさん入力した後、次の結果が得られました。

この結果は、エミュレータの複数のバージョンと一致しています。

横向きの問題を引き起こす静的サイズの制約を使用せずに、この問題を解決するにはどうすればよいですか?

4

4 に答える 4

1

ボタンを別々に分けて、これとを縦にRelativeLayout囲みます。ListViewLinearLayout

それで:

<LinearLayout android:id="@+id/linearLayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout [...]
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <!-- Your buttons -->
  </RelativeLayout>
  <ListView android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" />
</LinearLayout

ここで重要なのは、の高さと重量ListViewです。LinearLayoutこれは、ボタンにスペースが正しく割り当てられた後、残りのスペースを埋めることを意味します。

于 2011-07-08T20:01:08.303 に答える
0

listViewタグにandroid:weigthを追加し、android:weigthの値を1に設定します。これは、リストビューの高さと幅がfill_parentに設定され、リストビューがレイアウト全体をカバーしている場合に機能します。だからそれを試してみてください、それはうまくいくでしょう。

于 2011-07-08T20:07:06.703 に答える
0

簡単な解決策の 1 つは、ボタンを独自の相対レイアウトで分離し、全体を線形レイアウトに配置することです。次に例を示します。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#551A8B"
    android:textColor="#FFD700">
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#551A8B"
        android:textColor="#FFD700">
        <!-- your buttons -->
    </RelativeLayout>
    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textColor="#FFD700"
        android:layout_below="@id/button7"
        android:textSize="10sp">
    </ListView>
</LinearLayout>
于 2011-07-08T19:59:05.163 に答える
0

2 行のボタン (各行は LinearLayout として) を持つ垂直 LinearLayout を使用し、ListView に「1」の layout_weight 値を指定します。実際、layout_weight を使用して、ボタンのサイズもクリーンアップしてください。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button android:text="@string/New" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:id="@+id/button3" />

    <Button android:text="@string/Edit" 
    android:id="@+id/button4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_weight="1"  />

    <Button android:text="@string/Delete" 
    android:id="@+id/button5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_weight="1"  />
</LinearLayout>

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >    

    <Button android:layout_height="wrap_content" 
    android:id="@+id/button7" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/Previousweek" />

    <Button android:layout_height="wrap_content" 
    android:id="@+id/button6" 
    android:layout_width="wrap_content" 
    android:layout_weight="1"
    android:text="@string/Next" />
</LinearLayout>

<ListView android:id="@+id/listView1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_weight="1" 
android:textColor="#FFD700"
android:textSize="10sp" >
</ListView> 

于 2011-07-08T21:30:54.910 に答える