0

我想将 LineatLayout 放在屏幕底部。这个 LineraLayout 在他的父 Linearlayout 里面。我得到了屏幕的高度并根据它,我知道 setTop() 中的值是什么。但是 setTop() 没有做任何事情。我在单击按钮后使用 setTop,而不是在 onCreate 方法中,因此主布局已完全加载。

我尝试使用 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_CONTENTMATCH_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 回答