如何使用 LinearLayout 增加单选按钮的大小 [英] How to increase radio button size using LinearLayout
问题描述
我正在尝试增加 LinearLayout
中 RadioButton
的大小,它包装到 ScrollView
中,但它没有以任何方式工作.我尝试使用 .setScaleX()
和 .setScaleY()
之类的属性,但没有用.这是我的代码:
I am trying to increase the size of RadioButton
in LinearLayout
which wraps into ScrollView
but it is not working in any way. I tried to use property like .setScaleX()
and .setScaleY()
but it didn't work. Here is my code:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<LinearLayout
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="horizontal">
<TextView
android:text="Current location: "
android:textSize="16sp"
android:textStyle="bold"
android:paddingRight="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/current_location"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:sca
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/zone_types_list_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:orientation="vertical"
android:background="@drawable/room_type_border"/>
</ScrollView>
</LinearLayout>
使用 radioGroup 创建单选按钮的代码:
private LinearLayout listView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
listView = (LinearLayout) rootView.findViewById(R.id.zone_types_list_View);
}
private void addRadioButtons() {
if (getActivity() != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
radioGroup = new RadioGroup(mActivity);
for (String ss : typesList) {
radioButton = new RadioButton(mActivity);
radioButton.setText(ss);
radioButton.setTag(ss.trim());
radioGroup.addView(radioButton);
radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
String tag = (String) buttonView.getTag();
Log.i(TAG, "selected radio: " + tag);
submitZoneType(tag.trim());
}
}
});
}
/* radioGroup.setPivotX(0);
radioGroup.setPivotY(0);
radioGroup.setScaleX(2f);
radioGroup.setScaleY(2f); */
listView.addView(radioGroup);
}
});
}
}
如果我动态添加 radioGroup.setScaleX(2f)
,它会帮助我增加 RadioButton
的大小,然后增加 buttons
的其余部分隐藏在 layout
中并且滚动不起作用.我不明白为什么滚动不能像这样工作.有没有其他方法可以增加 RadioButtons
的大小?
If I add radioGroup.setScaleX(2f)
dynamically, it helps me to increase the RadioButton
s size but then rest of the buttons
hide in the layout
and scrolling not work. I am not understanding why scrolling is not working like this way. Is there any other way to increase the size of RadioButtons
?
推荐答案
有效
radioButton.setHeight(10);
radioButton.setWidth(5);
这篇关于如何使用 LinearLayout 增加单选按钮的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!