0

LineatLayout を画面の下部に配置したい。この LineraLayout は、親 Linearlayout 内にあります。私は画面の高さを取得し、それに応じて、setTop() 内にどのような値が入っているかを知っています。しかし setTop() は何もしません。onCreate メソッドではなく、ボタンをクリックした後に setTop を使用するので、メイン レイアウトは完全に読み込まれます。

使用しようとしまし LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height); たが、この場合 setTop メソッドはありません。

これが今の私のレイアウトですここに画像の説明を入力

これが私が達成したいことです

ここに画像の説明を入力

これは私のxmlファイルの一部です

<!-- parent-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@xml/background_generale"
    android:gravity="top|right|center"
    android:orientation="vertical"
    tools:context=".MainActivity" >

        <!-- child-->
        <LinearLayout
         android:id="@+id/layoutBottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/mainLayoutRaddoppiaBackground"
        android:gravity="bottom|center_horizontal"
        android:weightSum="1" >

       ...here there are the 4 buttons you can see in the image...


       <!-- end child-->
        </LinearLayout> 

<!-- end parent-->
 </LinearLayout> 

私は何をすべきか?

4

2 に答える 2

0
parms = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,   
RelativeLayout.LayoutParams.WRAP_CONTENT);
parms.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE); 

これにより、要素が親の下部に配置されます。レイアウトをその親全体に塗りつぶしたい場合は、に変更WRAP_CONTENTしてみてくださいMATCH_PARENT。しかし、実際にレイアウトを一番上に揃える部分は、rule私が追加したものです。

于 2013-01-28T08:40:52.627 に答える
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:background="@color/holo_grey"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:background="@color/blue_dark" >
</LinearLayout>

<LinearLayout
    android:id="@+id/llContent"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="vertical" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="openAdmin"
        android:text="ABC" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="openTasks"
        android:text="XYZ" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:background="@color/blue_dark" >
</LinearLayout>
</LinearLayout>
于 2013-01-28T09:22:25.030 に答える