如何在Android中为Button提供固定的宽度和高度 [英] How to give Fixed width and height for Button in Android

查看:104
本文介绍了如何在Android中为Button提供固定的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im beginner in android development. I ve just created a button in main.xml file

<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赋整数值:但是我得到了错误错误:错误:不允许使用整数类型

I just give integer value for android: but I got error error: Error: Integer types not allowed

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

How can give fixed width and height for Button here? and What is the main difference between android:layout_width and android:Width?

谢谢.

推荐答案

要创建具有固定高度和宽度的按钮,可以以px或dp形式提供值.

To create a button with fixed height and width, you can give values in both px or in dp.

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

giving values in dp is more convenient , bec android automatically scale the height and width in ldpi,mdpi and hdpi devices.

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

android:layout_width和android有什么区别:宽度

这篇关于如何在Android中为Button提供固定的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆