【问题标题】:Is there a way to stack the widgets from bottom in linearlayout?有没有办法在线性布局中从底部堆叠小部件?
【发布时间】:2019-05-07 18:09:31
【问题描述】:

定义Linearlayout 时,ButtonEdittext 等小部件将从顶部开始堆叠。 例如,下面的代码将显示为this

    <LinearLayout

        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:text="button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <EditText
            android:text="edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:text="button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <EditText
            android:text="edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

是否可以在不使用layout_weight的情况下从布局底部开始添加按钮和编辑文本?

【问题讨论】:

    标签: android layout android-linearlayout


    【解决方案1】:

    android:gravity="bottom" 添加到您的根布局中:

    <LinearLayout
    
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom" \\ add this line
        android:orientation="vertical">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button" />
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="edittext" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="button" />
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="edittext" />
    
    </LinearLayout>
    

    【讨论】:

    • 这很好,但是第一个按钮在添加其余按钮后向上移动。如何解决?
    • 这是您发布的相同代码我遇到了这个问题!
    • 我的意思是你的活动!
    猜你喜欢
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 2018-08-10
    相关资源
    最近更新 更多