如何在android studio中使用相对布局时使(按钮开启)屏幕响应?

问题描述 投票:0回答:1

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

这些是具有相对和线性布局的输出。我通过使用不同的线性布局尝试了很多,但它也无济于事。

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

android android-linearlayout responsive relativelayout
1个回答
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>

更高的屏幕:

enter image description here

更短的屏幕:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.