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

rej*_*ejo 2 android android-layout

我是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"
    />
Run Code Online (Sandbox Code Playgroud)

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

如何为Button提供固定的宽度和高度?android:layout_width和android:Width之间的主要区别是什么?

谢谢.

abb*_*efa 12

要创建具有固定高度和宽度的按钮,您可以在px或dp中给出值.

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

<Button 
    android:text="Click"
    android:layout_width="100dp"
    android:layout_height="50dp"
    />
Run Code Online (Sandbox Code Playgroud)

android:layout_width和android:width有什么区别?