2014-08-27 3 views
0

목록보기 항목에 대해 아래에 표시된 것과 같은 레이아웃을 만들어야합니다. 그러나 나는 그것을 창조하지 않으려 고 노력하고 있지만 나는 또한 성과에 대해서 생각하고있다. weight 속성을 가진 중첩 된 선형 레이아웃을 사용하여이 작업을 시도했지만, 내 응용 프로그램의 성능이 저하 될 수 있으므로 중첩 된 선형 레이아웃을 사용하는 것은 좋지 않습니다. 또한 상대 레이아웃을 사용하려고했지만 원하는 결과를 얻지 못했습니다. 가장 많은 공간이 가운데 텍스트보기에 표시됩니다. 도움을 미리 요청 해 주셔서 감사합니다.목록 항목을 만드는 모범 사례

enter image description here

+0

전체 항목의 높이를 알고 있거나 고정되어 있습니까? 중간에있는 텍스트 필드는 각각 수직 공간의 절반을 차지해야합니까? –

답변

0

어쩌면 내가 제대로 이해하지 않는 - 또는 어쩌면이 당신이 말한하지 않은 특정 요구 사항이 있지만, 나는 그것이 사용자의 요구에 맞게해야한다고 생각 : 음을

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="100dp" 
android:orientation="horizontal" 
android:weightSum="1"> 

<RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="0.25" 
    android:background="#8E7AE5"></RelativeLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="0.5" 
    android:background="#E57A7A" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#D5E57A" 
     android:gravity="center" 
     android:text="Top" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:gravity="center" 
     android:text="Down" /> 
</LinearLayout> 


<RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="0.25" 
    android:background="#8E7AE5"></RelativeLayout> 
</LinearLayout> 
0

을, I 이 일을 할 것입니다 :

<LinearLayout xmlns:andoird="http://schemas.android.com/apk/res/android" 
andoird:layout_width="match_parent" 
andoird:layout_height="48dp" 
andoird:orientation="horizontal" 
android:weightSum:1> 


<TextView 
    andoird:layout_width="0dp" 
    andoird:layout_height="match_parent" 
    andoird:layout_weight="0.25" 
    andoird:text="Left textView"/> 

<!-- Middle container --> 
<LinearLayout 
    andoird:layout_width="0dp" 
    andoird:layout_height="wrap_content" 
    andoird:layout_weight="0.5" 
    andoird:orientation="vertical"> 

    <TextView 
     andoird:layout_width="match_parent" 
     andoird:layout_height="24dp" 
     andoird:text="Middle Top textView"/> 

    <TextView 
     andoird:layout_width="match_parent" 
     andoird:layout_height="24dp" 
     andoird:text="Middle Bottom textView"/> 

</LinearLayout> 

<Switch 
    andoird:layout_width="0dp" 
    andoird:layout_height="match_parent" 
    andoird:layout_weight="0.25" 
    andoird:text="Right switch" /> 

T 그의 레이아웃은 성능에 대한 XML 경고를 던지지 않습니다. 성능에 관해서는 ListView 어댑터에서 ViewHolder를 사용해야합니다. 그것은 많은 도움이됩니다.

0

이 방법을 시도해보고 문제를 해결하는 데 도움이되기를 바랍니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.25" 
     android:gravity="center_vertical" 
     android:paddingLeft="10dp"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="textview"/> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.50" 
     android:orientation="vertical" 
     android:paddingLeft="10dp"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:gravity="center_vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="textview"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:gravity="center_vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="textview"/> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.25" 
     android:gravity="center_vertical" 
     android:paddingLeft="10dp"> 
     <Switch 
      android:id="@+id/main_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
</LinearLayout> 

참고 :는 우리가 당신의 요구 사항을 달성 할 수 무게의 LinearLayout을 사용하여 생각합니다.