android設置button間距
㈠ 安卓編程 如何在java代碼里設置button的margin(外邊距)
1、獲取按鈕的LayoutParams
LinearLayout.LayoutParamslayoutParams=(LinearLayout.LayoutParams)button.getLayoutParams();
2、在LayoutParams中設置margin
layoutParams.setMargins(100,20,10,5);//4個參數按順序分別是左上右下
3、把這純仔掘戚輪個LayoutParams設置給做核按鈕
button.setLayoutParams(layoutParams);//mView是控制項
㈡ 為什麼Android的button的字和上下邊緣的間距那麼大
layout_height="wrap_content"時, 還有一個好像叫minHeight設置一下, 具體名記不清了, 意思就是最小高度, 這個屬性會起作用
android:paddingLeft="100dp",不同手機的dpi不同,換算出來的實際像素圓或是不同的,所以看起來在橘姿伍不同的手機會冊戚不一樣
㈢ android 怎樣得到連續兩次單擊button的時間間隔
1、定義一個變數,記錄上一次單擊的時間
2、設置按鈕的點擊監聽事件,獲取本次單擊的時間
3、本地單擊的時間減去上次單擊的時間就是時間間隔。
示例
longprelongTim=0;//定義上一次單擊的時間
button01.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
if(prelongTim==0){//第一次單擊,初始化為本次單擊的時間
prelongTim=(newDate()).getTime();
}else{
longcurTime=(newDate()).getTime();//本地單擊的時間
System.out.println("兩次單擊間隔時間:"+(curTime-prelongTim));//計算本地和上次的時間差
prelongTim=curTime;//當前單擊事件變為上次時間
}
}
}
㈣ 如何設置兩個android:RadioButton間距
可以通過view 把他撐起來。
可以用maign的top的方磨櫻和法向上有多瞎盯少距離。
可以分倆個頌蠢布局來寫。
㈤ qtradiobutton設置文字與單選框距離
qtradiobutton設置文字與單選框距離
在使用radiobutton 的按鈕跟文字之間的間距在局宴不同的手機上會出現間距不一致,今天學習到了如何解決這個問題; 1使用android:button這個屬性來設置選擇框的自定義樣式,這時我們的會對其默認間距感到不滿意;
2隨後加入android:paddingLeft屬性來直接調整間距,看起來沒什麼問題,打到了我們要的效果,然而在一些機型上出了問題: 在字體會和選擇按鈕重疊: 這個是因為給控制項設置了padding導致,具體原因是radiobutton使用州臘明了一個透明的.9圖片作為背景 .9圖本身是可以現在內容的范圍的(相當於由.9圖控制的控制項的padding),當你再次設置padding就沖突了(具體怎麼個沖突法我 沒去探討),這個問題在API17修復了,但是我們依舊需要解決舊版本的問題冊告;
3於是各種查找以後找到了解決方法(我是er,我自豪),具體要設置如下: android:drawableLeft="@drawable/XXXX" android:button="@null" android:background="@null" android:drawablePadding="5dp" 原理是用drawableLeft代替原來的button屬性,並且將background移除(上面說的那個.9圖),然後通過android:drawablePadding 來設置間距. 下面是一個列子,效果就很普通拉,就不貼圖了
<RadioButton
android:id="@+id/rb_net_type1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="2G/3G/4G移動網路"
android:textSize="14dp"
android:textColor="@color/text1"
android:drawableLeft="@drawable/selector_feedback_radiobutton"
android:button="@null"
android:background="@null"
android:drawablePadding="5dp"
/>
㈥ Android怎麼讓LinearLayout的兩個按鈕之間存在一些間隔
可以按照以下代碼進行嘗試:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="肆裂wrap_content"
android:orientation="vertical"
android:padding="10dp"
>
<Button
android:id="@+id/btnAction1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/cool_button"
android:text = "HiText1"
/>
<Button android:layout_marginTop="50dp"
android:id="@+id/btnAction2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/cool_button"
android:text="數雹州HiText2"
android:layout_below="@id/btnAction1"
/>
</LinearLayout>
(6)android設置button間距擴展閱讀
若設置一個控制項為android:graviity="center|top" 那麼這個控制項中的子控制項位於該控制項的中心位置靠上的部位。
若設置一個控制項為android:layout_gravity="center|top" 那麼這個控制項位於他父控制項薯蔽的中心位置靠近上的部位,是對這個控制項本身位置的操作。
android:layout_marginBottom:離某元素底邊緣的距離
android:layout_marginLeft:離某元素左邊緣的距離
android:layout_marginRight:離某元素右邊緣的距離
android:layout_marginTop:離某元素上邊緣的距離
㈦ android 怎樣讓兩個button控制項挨在一起,左右對齊 沒有距離
Android中兩個Button可以使用線性布局LinearLayout來包含。
控制項之間的間距有兩種設置:
android:layout_margin="10dp" 外邊距
android:padding="10dp" 內邊距
在Button中將android:layout_margin="0dp" android:padding="0dp"
即將內外兩個間距都設置為0即可