当前位置:首页 » 安卓系统 » android设置button大小

android设置button大小

发布时间: 2024-09-11 15:25:36

A. android布局里的Button排列问题

这样可以完全达到你的要求,并且屏幕怎么变都行

java"><LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>

B. 在Android编程模式下,如何设置Button为自动适应

  1. 得到屏幕灶侍的高度h隐扒吵button。setheight(h/16)(此处还有其此槐他的方法自己去试一下)(此处的前提是button在垂直的线性布局中)

2. 通过 layoutparams 去设置 高度和宽度

C. android开发中如何设置ImageButton的大小

在Android开发中,java代码用于将zoom设置为fitxy,从而使类能够继承uibutton、重写button和设置ImageView size来设置imagebutton的大小,具体Java设置代码如下:

<ImageButton

android:id="@+id/btn_delete"

android:layout_width="48dp"

android:layout_height="80dp"

android:scaleType="fitXY"

android:background="@drawable/bg_sms"/>

此外,Android还包括一些C/C++库,这些库可以被Android系统中的不同组件使用,他们通过Android应用程序框架为开发人员提供服务。

(3)android设置button大小扩展阅读:

Android应用软件开发语言有C语言等多种语言,但主流的开发语言是java语言,这使得界面的功能有了无尽的变化,增加软件交互的可能性是Java的最大特点。

所有的Android应用程序都是用Java语言编写的,用java语言开发的软件程序库、数据库和运行库是Android移动软件的主要特点。

Java语言是增长最快的编程语言,它具有面向对象的特点,它相对容易理解,它的显着特点是简单,它继承了C++语言的高级本质,它是计算机程序设计语言发展的一大进步,Java语言有一个独立的体系结构,可以在任何系统中任意运行。

D. android 如何自动调整button宽度

  1. 权重 layout-weight,搞几个看不见的布局布满整个宽度

  2. 获取屏幕宽度X,然后setwidth(X/N)

  3. wrapcontent 然后paddingright paadingleft。。。

E. 如何自定义android Button样式

返回博客列表
转 android自定义button样式

sumpower
发布时间: 2014/02/25 19:56

阅读: 4162

收藏: 0

点赞: 0

评论: 0
摘要
android自定义button样式

在Android开发应用中,默认的Button是由系统渲染和管理大小的。而我们看到的成功的移动应用,都是有着酷炫的外观和使用体验的。因此,我们在开发产品的时候,需要对默认按钮进行美化。在本篇里,笔者结合在应用开发中的经验,探讨一下自定义背景的按钮、自定义形状按钮的实现方法。
首先看实现效果截图:

自定义背景的按钮目前有2种方式实现,矢量和位图。

1. 矢量图形绘制的方式
矢量图形绘制的方式实现简单,适合对于按钮形状和图案要求不高的场合。步骤如下:
(a) 使用xml定义一个圆角矩形,外围轮廓线实线、内填充渐变色,xml代码如下。
view plain
//bg_alibuybutton_default.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="地址">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFEC7600" />
<corners
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
</shape>
</item>
<item android:top="1px" android:bottom="1px" android:left="1px" android:right="1px">
<shape>
<gradient
android:startColor="#FFEC7600" android:endColor="#FFFED69E"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
<corners
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
</shape>
</item>
</layer-list>
同样定义bg_alibuybutton_pressed.xml和bg_alibuybutton_selected.xml,内容相同,就是渐变颜色不同,用于按钮按下后的背景变化效果。
(b) 定义按钮按下后的效果变化描述文件drawable/bg_alibuybutton.xml,代码如下。
view plain
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="地址">
<item android:state_pressed="true"
android:drawable="@drawable/bg_alibuybutton_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/bg_alibuybutton_selected" />
<item android:drawable="@drawable/bg_alibuybutton_default" />
</selector>
(c) 在你需要的界面定义文件中,如layout/main.xml中定义一个Button控件。
view plain
<Button
android:layout_width="120dip"
android:layout_height="40dip"
android:text="矢量背景按钮" android:background="@drawable/bg_alibuybutton" />
这样,自定义背景的按钮就可以使用了,在实现onClick方法后就可以响应操作。

F. android studio中的button有哪些方法

先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下: public Button(Context context, AttributeSet attrs) { this(context, attrs, com.android.internal.R.attr.buttonStyle); } 1 2 3 其中com.android.internal.R.attr.buttonStyle就是我们修改样式的关键了,网上的教程的修改方法大都是: <Button style="@style/ButtonStyle" android:layout_width="wrap_content" android:layout_height="40dp" android:layout_weight="1" android:text="价格" /> 1 2 3 4 5 6 也就是在对应的xml里面button控件里面编写style达到目的。 但是如果我们的app需要完全统一整个应用的button的样式,那么就需要在每一个button里面添加style。 这显然效率太低下了。 接下来打开我们项目中values文件夹下面的styles.xml文件,我们创建安卓项目的时候,会有一个默认的styles文件。 打开之后找到这段代码: <style name="AppBaseTheme" parent="Theme.Holo.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> 1 2 3 4 5 6 7 8 9 10 不保证读者的默认styles.xml和我的是一样的,不过大概是这个样子,有可能读者的最低支持是2.3、那么就没有Them.Light。 我们使用eclipse的快捷键打开这个Theme.Holo.Light。可以看到如下代码: <style name="Theme.Holo.Light" parent="Theme.Light"> <item name="colorForeground">@android:color/bright_foreground_holo_light</item> <item name="colorForegroundInverse">@android:color/bright_foreground_inverse_holo_light</item> <item name="colorBackground">@android:color/background_holo_light</item> <item name="colorBackgroundCacheHint">@android:drawable/background_cache_hint_selector_holo_light</item> <item name="disabledAlpha">0.5</item> <item name="backgroundDimAmount">0.6</item>

热点内容
pythonlist添加dict 发布:2024-09-18 05:29:51 浏览:903
我的世界花雨庭服务器怎么开宝箱 发布:2024-09-18 05:17:45 浏览:463
google云服务器申请 发布:2024-09-18 05:03:14 浏览:558
centos7启动脚本 发布:2024-09-18 05:01:40 浏览:619
美图手机的文件夹 发布:2024-09-18 04:55:10 浏览:441
python常见编程题 发布:2024-09-18 04:30:54 浏览:768
安卓手机的资料怎么导到苹果手机 发布:2024-09-18 04:30:54 浏览:89
zookeeper编译 发布:2024-09-18 04:10:44 浏览:585
军舰访问大连 发布:2024-09-18 04:10:43 浏览:683
江苏云服务器虚拟主机物理机 发布:2024-09-18 03:52:50 浏览:548