gpt4 book ai didi

android - 如何在 Android 中为 Button 提供固定的宽度和高度

转载 作者:太空狗 更新时间:2023-10-29 15:33:53 26 4
gpt4 key购买 nike

我是 Android 开发的初学者。我刚刚在 main.xml 文件中创建了一个按钮

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



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

我只是给android的整数值:但我得到了错误错误:错误:不允许整数类型

这里如何给Button设置固定的宽度和高度?和android:layout_width 和 android:Width 之间的主要区别是什么?

谢谢。

最佳答案

要创建一个具有固定高度和宽度的按钮,您可以以 px 或 dp 为单位提供值。

在 dp 中给出值更方便,因为 android 会自动缩放 ldpi、mdpi 和 hdpi 设备的高度和宽度。

<Button 
android:text="Click"
android:layout_width="100dp"
android:layout_height="50dp"
/>

What is the difference between android:layout_width and android:width

关于android - 如何在 Android 中为 Button 提供固定的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9408174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com