我正在android中构建我的第一个应用程序。我也在使用ActionBarSherlock。我现在想要开发的是一个对话框,在radioGroup的顶部和下方显示一个radioGroup一个列表。我已经这样做了,但是我的项目列表上位于左侧。有什么办法可以让它们位于中间吗?谢谢您的时间
这是xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:checked="true"
android:text="Justified" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Unjustified" />
</RadioGroup>
<customAdapter.MyListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp" >
</customAdapter.MyListView>
这是实际的代码:
public static class MyDialogFragment extends SherlockDialogFragment {
int mNum;
RadioButton btn1;
RadioButton btn2;
/**
* Create a new instance of MyDialogFragment, providing "num"
* as an argument.
*/
static MyDialogFragment newInstance(int num) {
MyDialogFragment f = new MyDialogFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments().getInt("num");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.myfrg, container, false);
ListView lv = (ListView) v.findViewById(R.id.list);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,justifiedAbsences);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
lv.setAdapter(dataAdapter);
return v;
}
}
这是在我添加了 fravity="center" 之后
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity = "center" >
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:checked="true"
android:text="Justified" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Unjustified" />
</RadioGroup>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp" >
</ListView>