代码之家  ›  专栏  ›  技术社区  ›  Huzo

是否可以将视图移动到线性布局中最左下角?

  •  0
  • Huzo  · 技术社区  · 6 年前

    所以,这是我的观点

    enter image description here

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp">
    
        <TextView
            style="?android:listSeparatorTextViewStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/crime_title_label" />
    
        <EditText
            android:id="@+id/crime_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/crime_title_hint" />
    
        <TextView
            style="?android:listSeparatorTextViewStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/crime_details_label" />
    
        <Button
            android:id="@+id/crime_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <CheckBox
            android:id="@+id/crime_solved"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/crime_solved_label" />
    
    </LinearLayout>  
    

    我想在最左下角加一个按钮。但我不确定在垂直方向的线性布局中是否可以实现。在不改变布局类型的情况下,我想到的唯一方法是将此部分添加到我想要的按钮: android:layout_gravity="bottom|left" 但这并不能起作用。有什么建议吗?如果能用线性布局来解决,我会很高兴的。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Deividas Strioga    6 年前

    我认为这是最短的解决方案,虽然我不能不包括额外的布局。将其添加到xml的末尾(仍在LinearLayout中)。

    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom" />
        </FrameLayout>