【问题标题】:Android Studio: I can’t make button be at the bottom of screenAndroid Studio:我不能让按钮位于屏幕底部
【发布时间】:2018-05-25 05:26:20
【问题描述】:

我用红色标记了它应该是什么,我需要更改组件树的当前元素的属性,我不想删除它们或添加另一个。

文本视图:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">
    <com.camera.test.ui.camera.CameraSourcePreview
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.camera.test.ui.camera.GraphicOverlay
            android:id="@+id/graphicOverlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/footer"
            android:gravity="center">
            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_centerHorizontal="true"
                android:background="@drawable/icon"
                android:onClick="Categories"
                android:text="BUTTON"
                android:textColor="#228496"
                android:textSize="21sp" />
        </RelativeLayout>
    </com.camera.test.ui.camera.CameraSourcePreview>
</LinearLayout>

【问题讨论】:

  • 你是把这个项目导入android studio还是更新android studio?
  • 建议大家了解一下LinearLayout、RelativeLayout、ConstraintLayout的区别。
  • @Wahdat Kashmiri 我改变了当前打开的项目,反正已经有了很好的答案。

标签: android android-layout android-studio user-interface layout


【解决方案1】:

如果你想在屏幕下方提供一个按钮,则使用相对布局作为父级并赋予属性 alignparentbottom,如果你坚持使用 LinearLayout 作为父级,则使用它,

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"/>

</LinearLayout>

注意:请进行 Gradle 同步,即使未加载,请更改您的 Gradle

    compileSdkVersion 26
buildToolsVersion '26.0.2'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'

【讨论】:

    【解决方案2】:

    为什么使用水平线性布局作为顶层。 您可以将相对布局用作顶层,并在内部相对布局中添加属性 android:layout_alignParentBottom="true"

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 2013-07-14
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多