简体   繁体   English

Android对齐按钮位于列表视图下方的右下角

[英]Android align button to bottom right under a listview

I have no idea on how to achieve this layout: 我不知道如何实现这种布局: 在此输入图像描述 So basically I want a title bar, bellow that I want a listview, while anchored to the bottom I want a button in the right side of the screen. 所以基本上我想要一个标题栏,下面我想要一个列表视图,而锚定到底部我想要一个屏幕右侧的按钮。

Right now I am trying with this code (unsuccessfully) 现在我正在尝试使用此代码(失败)

<?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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text"
            android:id="@+id/textView" />
    </LinearLayout>

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

        <ListView
            android:layout_width="match_parent"
            android:layout_height="436dp"
            android:id="@+id/listView"
            android:layout_gravity="right" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        android:weightSum="1">

        <Button
            android:id="@+id/button_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="ok"
            android:layout_weight="0.45" />
    </LinearLayout>

</LinearLayout>

By using this layout, my listview does not resize when changing from portrait to landscape so my bottom button goes out of screen. 通过使用此布局,我的列表视图在从纵向更改为横向时不会调整大小,因此我的底部按钮会退出屏幕。 Also the bottom button is not aligned to the right side. 底部按钮也没有与右侧对齐。

Any idea on how to achieve this? 有关如何实现这一点的任何想法? So I need 2 "bars" one anchored to the top, and one anchored to the bottom. 所以我需要2个“杆”,一个固定在顶部,一个固定在底部。 On the top "bar" I want a TextView, and on the bottom "bar" I want a button aligned to the right. 在顶部“栏”我想要一个TextView,在底部的“栏”我想要一个右边对齐的按钮。 And I want the listView to fill the space between the 2 bars. 我希望listView填充2个栏之间的空间。 So there may be empty space in the middle, when listview has just 1-2-3 items (just like in the picture). 因此,当listview只有1-2-3个项目时,中间可能会有空白空间(就像在图片中一样)。

Can this be done? 可以这样做吗? Please advise... 请指教...

Change your top layout to a relatuve layout, then place the button outside your linearlayout and inside your relative layout. 将顶部布局更改为相关布局,然后将按钮放在线性布局外部并放在相对布局内。 Then set gravity layout_gravity to bottom||right 然后将gravity layout_gravity设置为bottom || right

U can also drag t where u want it in the visual part of the xml layout 你也可以在xml布局的可视部分中拖动你想要它的地方

Change your top layout to a relatuve layout, then place the button outside your linearlayout and inside your relative layout. 将顶部布局更改为相关布局,然后将按钮放在线性布局外部并放在相对布局内。 Then set gravity of the button tolayout_gravity to bottom||right 然后将按钮的重力设置为tolayout_gravity到底部||右边

U can also drag t where u want it in the visual part of the xml layout 你也可以在xml布局的可视部分中拖动你想要它的地方

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM