2010-05-31 4 views
2

다음 레이아웃을 만들었습니다.안드로이드 회 전자 너비 문제가 있습니까?

<TableLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 
     <TableRow> 


<TextView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Post As" /> 


<Spinner 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/ddlPostAs" 
     /> 
     </TableRow> 
     <TableRow> 
<TextView android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="Expires In" /> 

<Spinner 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/ddlExpiryOn" 

     /> 
</TableRow> 
</TableLayout> 

안드로이드 회 전자가 데이터에 따라 그 폭을 변경합니다. 나는 그것을 멈추고 싶다.

어느 하나가 이것을 달성하는 방법을 안내해 줄 수 있습니까?

어떤 도움

은 appriciated 될 것이다.

답변

5

화면의 너비에 따라 너비를 고정합니다. 화면에 고정 너비를 조정하기 위해 <TableRow>에 "weightSum 안드로이드를"당신은 사용할 수 있습니다

DisplayMetrics d = new DisplayMetrics(); 
getWindow().getWindowManager().getDefaultDisplay().getMetrics(d); 
int wdt = d.widthPixels; 
ddlpostas.getLayoutParams().width = wdt - 120; 
ddlexpiryon.getLayoutParams().width = wdt - 120; 
2

.

예 : 당신의 스피너 폭이 TableRow의 절반 너비로 설정됩니다이 코드에 의해

<TableRow android:weightSum="2"> 

      <TextView android:layout_width="0dp" 
       android:layout_gravity="center_vertical" 
       android:layout_height="wrap_content" android:text="Post As" 
       android:layout_weight="1"/> 

      <Spinner 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:id="@+id/ddlPostAs" 
       android:layout_weight="1" 
       /> 
     </TableRow> 

.

귀하의 요구 사항에 따라 android : weightSum 및 android : layout_weight 값을 변경하십시오.