【问题标题】:How to make a (buttons on)screen responsive while using relative layout in android studio?如何在android studio中使用相对布局时使(按钮)屏幕响应?
【发布时间】:2019-01-03 06:47:41
【问题描述】:

有没有办法将按钮放置在具有自对齐空间的线性布局中?我一直在使用相对布局,但问题是我的屏幕没有保持响应,那么如何在使用相对布局时使其响应?或者如何在线性布局中添加空格并根据我的高度和宽度放置我的按钮?

这些是具有相对布局和线性布局的输出。我已经尝试了很多使用不同的线性布局,但也没有用。

this is the output with relative layout,but it is not responsive

this is output with linear layout, where spaces are not being added by me

【问题讨论】:

  • 您可以使用ConstraintLayout 尝试此操作也请分享您的 XML 代码,以便有人知道您在尝试什么。

标签: android android-linearlayout responsive android-relativelayout


【解决方案1】:

你可以试试这样的:

<?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:orientation="vertical">

    <android.widget.Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Button One" />

    <android.widget.Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Button Two" />

    <android.widget.Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Button Three" />

    <android.widget.Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Button Four" />

    <android.widget.Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <Button
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Button Five" />

    <android.widget.Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

更高的屏幕:

屏幕更短:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多