在切换按钮设置相同的高度宽度 [英] Set same height as width at a ToggleButton
本文介绍了在切换按钮设置相同的高度宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下布局,连续7的ToggleButtons。独立于分辨率,我一直在整个水平宽度7个按键。现在,我想设置相同的高度,宽度,但它不工作。
我尝试以下没有成功():
I have following Layout, with 7 ToggleButtons in a row. Independently from the resolution, I have always 7 Buttons in the complete horizontal width. Now I want to set the same height as the width but it does not work. I tried following without success ():
tb_Mo = (ToggleButton) findViewById(R.id.tB_Mo);
int btnSize=tb_Mo.getWidth();
tb_Mo.setHeight(btnSize);
//and so on for the other Buttons...
第二次尝试没有成功:
Second try without success:
int btnSize=tb_Mo.getLayoutParams().width;
tb_Mo.setLayoutParams(new LinearLayout.LayoutParams(btnSize, btnSize));
//and so on for the other Buttons...
XML:
XML:
<ToggleButton
android:id="@+id/tB_Mo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/btntoggle_selector"
android:textColor="@android:color/white"
android:textOff="OFF"
android:textOn="ON"
android:layout_weight="1"/>
<ToggleButton
android:id="@+id/tB_Di"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/btntoggle_selector"
android:textColor="@android:color/white"
android:textOff="OFF"
android:textOn="ON"
android:layout_weight="1"/>
<ToggleButton
android:id="@+id/tB_Mi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/btntoggle_selector"
android:textColor="@android:color/white"
android:textOff="OFF"
android:textOn="ON"
android:layout_weight="1"/>
and so on ....
我该怎么办?
推荐答案
解决方案:
<ToggleButton
android:id="@+id/tB_Sa"
android:layout_width="0dp"
android:layout_height="50dp"
android:background="@drawable/btntoggle_selector"
android:textColor="@android:color/white"
android:textOff="OFF"
android:textOn="ON"
android:layout_weight="1"/>
和
int btnSize=tb_Mo.getWidth();
tb_Mo.setHeight(btnSize);
这篇关于在切换按钮设置相同的高度宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文