當前位置:首頁 » 安卓系統 » 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>

熱點內容
androideclipse目錄 發布:2024-09-19 16:10:37 瀏覽:931
linux系統是什麼系統 發布:2024-09-19 16:10:35 瀏覽:119
資料庫財經 發布:2024-09-19 16:03:23 瀏覽:934
直接腳本 發布:2024-09-19 15:49:09 瀏覽:239
安卓代碼怎麼用 發布:2024-09-19 15:35:38 瀏覽:384
微信為什麼要用伺服器 發布:2024-09-19 15:35:29 瀏覽:882
東芝硬碟加密 發布:2024-09-19 15:29:44 瀏覽:138
天刀演奏腳本那個好用 發布:2024-09-19 15:29:43 瀏覽:97
sql列號查詢 發布:2024-09-19 14:58:07 瀏覽:433
華為watchfit如何連接安卓手機 發布:2024-09-19 14:36:47 瀏覽:977