0

私はアンドロイドで私の最初のアプリケーションを構築しています.私は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>

4

3 に答える 3

1

独自のレイアウトをリスト項目に拡張する必要があります。リスト項目は次のようになります

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">  

    <!-- List item name -->
    <TextView
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">
    </TextView>
</RelativeLayout>
于 2012-11-19T11:49:40.227 に答える
0

あなたのライン上

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

レイアウトをテキスト中心の新しいレイアウトに変更する必要があります。

于 2012-11-19T11:47:09.330 に答える
0

これが最後の結果です..

<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"
    android:gravity="center" >

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Justified" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            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>

于 2012-11-19T11:54:16.430 に答える