LinearLayout问题中的按钮

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

我有一个自定义对话框,其中有3个按钮,有时只有一个按钮。当我有3个按钮时,LinearLayout恰好适合这些按钮。但是,当我只有一个按钮时,它使单个按钮的整个宽度可用,从而使该按钮看起来太大。我想要的是,如果只有一个按钮,它应该只占可用整个宽度的一半,或者应该包装内容(按钮图像。)请参阅以下图像以供参考-

““>

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9QWFN3Qi5wbmcifQ==” alt =“ 1按钮对话框”>“>

我有一个自定义对话框,其中有3个按钮,有时只有一个按钮。当我有3个按钮时,LinearLayout本身非常适合这些按钮。但是当我只有一个按钮时,它会给出...

android button dialog android-linearlayout
2个回答
3
投票

请参阅与您的要求相似的XML文件。只是可见性转到不需要的按钮。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" android:weightSum="3" android:gravity="center_horizontal">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button"/>


    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button"/>

</LinearLayout>

1
投票

[使一个按钮占用所需屏幕宽度的一半

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