我正在嘗試增加RadioButton
的大小LinearLayout
,該大小寫入ScrollView
,但它不以任何方式工作。我試圖使用像.setScaleX()
和.setScaleY()
這樣的屬性,但它不起作用。這裏是我的代碼:如何使用LinearLayout增加單選按鈕大小
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
的大小?
你能檢查myanswer嗎?@ user565 – KeLiuyue