当前位置:首页 » 安卓系统 » android设置button间距

android设置button间距

发布时间: 2023-05-04 21:39:38

㈠ 安卓编程 如何在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的字和上下边缘的间距那么大

  1. layout_height="wrap_content"时, 还有一个好像叫minHeight设置一下, 具体名记不清了, 意思就是最小高度, 这个属性会起作用

  2. 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间距

  1. 可以通过view 把他撑起来。

  2. 可以用maign的top的方磨樱和法向上有多瞎盯少距离。

  3. 可以分俩个颂蠢布局来写。

㈤ 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来包含。

控件之间的间距有两种设置:

  1. android:layout_margin="10dp" 外边距

  2. android:padding="10dp" 内边距

在Button中将android:layout_margin="0dp" android:padding="0dp"

即将内外两个间距都设置为0即可

热点内容
linux用户空间与内核空间 发布:2025-05-19 23:26:59 浏览:799
python条件与 发布:2025-05-19 23:26:56 浏览:187
python回测框架 发布:2025-05-19 23:19:28 浏览:724
单片机的压缩算法 发布:2025-05-19 23:18:06 浏览:273
电脑怎么配置桌面分区 发布:2025-05-19 23:15:23 浏览:655
房车里的鸡肋配置有哪些 发布:2025-05-19 23:13:41 浏览:611
溯源码平台 发布:2025-05-19 22:59:37 浏览:251
c语言课程报告 发布:2025-05-19 22:52:38 浏览:237
编程软件e 发布:2025-05-19 22:51:00 浏览:128
手机壁纸安卓app哪个最好用 发布:2025-05-19 22:50:06 浏览:47