0

相対的なレイアウトを下に移動するには、どのような変更を加える必要がありますか?

      <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="86dp"
    android:layout_alignParentBottom="true"
    android:layout_weight="0.08"
    android:gravity="bottom" >
   </RelativeLayout>
      </LinearLayout>
4

4 に答える 4

1

RelativeLayoutこの属性は子android:layout_alignParentBottomに対して何もしないため、親の Layout を に変更する必要があります。LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="86dp"
        android:layout_alignParentBottom="true" >
    </RelativeLayout>
</RelativeLayout>
于 2013-08-23T19:32:09.277 に答える
0

使用する

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

    <!-- replace this by any other layout or view. You might want something here, right? -->    
    <View android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="86dp">
    </RelativeLayout>

</LinearLayout>
于 2013-08-23T19:42:23.773 に答える
0

デフォルトでは子を上から下に積み重ねるため、 a のFrameLayout代わりに aを使用することでそれを実現できます。LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="86dp"
        android:layout_gravity="bottom" >
    </RelativeLayout>

</FrameLayout>
于 2013-08-23T19:31:39.983 に答える
0

ここには 2 つの問題があります。一つ目はそれ

android:gravity

間違っている。これgravityにより、この子のコンテンツの が設定されViewます。たとえば、 で使用すると、TextViewtext場合は を一番下に配置しTextViewます。代わりに欲しいのは

android:layout_gravity

これにより、その親内にViewsが設定されます。gravity

2 番目の問題は 、 who のisandroid:gravity="bottom"で期待どおりに機能しないことです。理由をうまく説明できるかどうかわからないので、それを説明するリンクを少し見つけようとします。しかし、 の を に変更すると、これが表示されます。LinearLayoutorientationverticalorientationLinearLayouthorizontal

したがって、可能であればを変更し、orientationそうでない場合はルートViewGroupを aに変更し、誰かがすでに提案したRelativeLayoutようにプロパティを使用することをお勧めします。android:alignParentBottom="true"

説明のために編集

このブログ投稿この SO answer、とりわけそれについて少し説明します。しかし基本的に、 が である場合、はorientation期待どおりに左から右に配置されるため、 left と right を制御することはできません。を使用すると、上と下に同じことが当てはまります。なぜなら、それらが垂直に配置される場所は、それを設定したときに Android によって既に決定されているからです。これが理にかなっていることを願っています。horizontalViewgravityvertical orientationgravityorientation

于 2013-08-23T19:55:45.420 に答える