0

我建立在android.I'm我的第一个应用程序也使用我现在要发展ActionBarSherlock.What是显示在顶部具有radioGroup中和radioGroup中一个list.I下面的对话?已经做的话,但我的名单上的项目定位到left.Is有什么办法可以让他们在中心位置感谢您的时间listItems中的位置

这是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 = “中心”

<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> 

+0

我们能有一些代码请! ? –

回答

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> 
0

您的线路上

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

你应该布局改变到一个新的文本的同居中。

+0

你的意思是创建一个新的? – user1746708

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> 

+0

我试过了,但它没有任何区别 – user1746708

+0

它是什么布局?有关系吗?帧? – Henrik

+0

噢噢..我看到了..它是线性..改变你的布局类型..帧..或相对.. – Henrik