2012-01-14 15 views
0

メニューバーを画面上部に表示する方法を知りました。私はexpandableListViewを使用して作成したメインメニューの周りを移動する間、その位置にとどまります。しかし、私は、メニューバーを画面の一番上ではなく下にしたいと思います。私はrelativeViewで遊んだり、下のバーを手に入れましたが、メインメニューは消えてしまいました。ここ は私のメインのxmlファイルは、その後、私はそれが私のプログラムに表示されるように取得するためにJavaのためにこれを使用しExpandableListViewの使用中に画面下部にメニューバーを置く

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 


<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/buttonbefore" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="50" 
     android:text="back" /> 

    <Button 
     android:id="@+id/buttonnext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="50" 
     android:text="Next" /> 
</LinearLayout> 

<ExpandableListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

<TextView 
    android:id="@+id/android:empty" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="@string/main_no_items" /> 

です。

LinearLayout bottomMenu = (LinearLayout)findViewById(R.id.buttons); 

私は重力で遊んでみましたが、何もしませんでした。あなたがそれが助けになると思うなら私のプログラムからもっと多くのコードを追加することができます。

答えて

2

buttons LinearLayoutはあなたが参照している「メニューバー」ですか?

あなたは、RelativeLayoutまたはLinearLayoutのいずれかを使用して、探しているものを実際に達成することができます。

のLinearLayout:

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <ExpandableListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 

     <TextView 
      android:id="@android:id/empty" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="@string/main_no_items" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/buttons" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/buttonbefore" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="back" /> 

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

</LinearLayout> 

リストはそれを「1」の重みを与えると設定することで、他のすべての利用可能なスペースを取るように言われている間、ボタンは、下揃え重力を設定することです高さは「0dp」です。これにより、ボタンを画面外に押さなくてもできるだけ引き伸ばされます。

RelativeLayout:

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/buttons" 
     android:orientation="vertical" > 

     <ExpandableListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 

     <TextView 
      android:id="@android:id/empty" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="@string/main_no_items" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/buttons" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/buttonbefore" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="back" /> 

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

</RelativeLayout> 

ボタンが下揃え親上のアライメントを設定することです。リストにはすべての高さを記入するよう指示されますが、ボタンの上に留まります。

一般的な注意点:これが機能するには、リストと空のビューをそれぞれのレイアウトで組み合わせる必要があると私は確信しています。

+0

ありがとう、私は別のLinearLayoutを追加してボタンを2番目のLinearLayout – Aaron

0

ボタンを最下部に揃える方法は、トップレベルのLinearLayoutをRelativeLayoutに変更することです。次に、2つのボタンを保持するLinearLayout @+id/buttonsに属性android:layout_alignParentBottom="true"を追加することができます。

関連する問題