2017-09-25 11 views
0

TableLayout에 대한 수정 사항을 공유하십시오. 필요에 따라 레이아웃을 정렬하기 위해 가중치와 열을 설정하는 방법에 대해 약간 혼란스러워하십시오. layout_span을 기반으로하여 서식 지정 요구 사항을 얻으시기 바랍니다. 그러나 말로 설명하려고 노력할 것입니다. 폭에 걸쳐 Android TableLayout 문제 - 올바르게 설정하지 못했습니다.

  • 두 번째 행에 걸친 버튼을 가지고 - - 나는 레이아웃을

    1. 첫 번째 행을 시각화하는 방법을 아래로 두는 것은 두 TextViews을 가지고 50 %의 영역을 복용 - 제목 센터 정렬
    2. 세 번째 행이하는 각
    3. 4 번째 행 - 정렬 된 제목 센터
    4. 다섯 번째 행 - 너비의 16.6 %를 차지하는 ImageView와 나머지 83.3 %를 차지하는 TextView를 갖습니다.
    5. 6 번째 행 - 너비가 16.6 % 인 하나의 ImageView와 나머지 83.3 %를 차지하는 TextView가 있습니다. 여기

  • 코드입니다 :

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        > 
    
        <TableRow 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         android:padding="10dp"> 
         <Button 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/app_get_questions" 
          android:id="@+id/btnNext" 
          android:textColor="@color/windowBackground" 
          android:layout_span="4" 
          android:layout_column="1" 
          /> 
        </TableRow> 
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         > 
         <TextView 
          android:layout_height="wrap_content" 
          android:gravity="center_horizontal" 
          android:text="@string/app_scoring_leaders" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textStyle="bold" 
          android:layout_span="4" 
          android:layout_column="1" 
          android:padding="5dp"/> 
        </TableRow> 
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         android:padding="5dp"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:id="@+id/txtDailyScores" 
          android:text="1. Kapil Bhagia (34511)\n2. Hardik Bhagia (2231)" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:layout_margin="5dp" 
          android:layout_column="1" 
          android:layout_span="2" 
          android:layout_weight="3"/> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:id="@+id/txtAllTimeScores" 
          android:text="1. Kapil Bhagia (34511)\n2. Hardik Bhagia (2231)" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:layout_margin="5dp" 
          android:layout_column="3" 
          android:layout_span="2" 
          android:layout_weight="3"/> 
        </TableRow> 
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         > 
         <TextView 
          android:layout_height="wrap_content" 
          android:gravity="center_horizontal" 
          android:text="@string/app_get_started" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textStyle="bold" 
          android:layout_column="1" 
          android:layout_span="4" 
          android:padding="5dp"/> 
        </TableRow> 
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         android:padding="5dp"> 
         <ImageView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:src="@drawable/ic_assessment_black_36dp" 
          android:layout_gravity="center_vertical" 
          android:layout_column="1" 
          android:layout_span="1" 
          android:layout_weight="1" 
          /> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/app_intro" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:layout_margin="5dp" 
          android:layout_column="2" 
          android:layout_span="3" 
          android:layout_weight="5"/> 
    
        </TableRow> 
        <TableRow 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         android:padding="5dp"> 
         <ImageView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center_vertical" 
          android:src="@drawable/ic_today_black_36dp" 
          android:layout_column="1" 
          android:layout_span="1" 
          android:layout_weight="1" 
          /> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center_vertical" 
          android:gravity="left" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:text="@string/app_base_score" 
          android:layout_margin="5dp" 
          android:layout_column="2" 
          android:layout_span="3" 
          android:layout_weight="5"/> 
        </TableRow> 
    </TableLayout> 
    

    답변

    0

    이 조금 시간이 걸렸습니다하지만 난해야 할 일을했을 것을 layout_weight를 관련 변경 사항이 전체 테이블의 구조를 변경했다. 마지막 두 행 대신 LinearLayout을 사용했습니다. 처음 네 행은 TableLayout을 사용하여 수행 할 수 있습니다. Layout_spans는 단순화해야했습니다. 복잡한 레이아웃을 가질 수없는 것 같습니다. 더 나은 해결책이 있는지 이해하기 쉽습니다.

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        > 
    
        <TableRow 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:padding="5dp" > 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/app_rankgrade" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textStyle="bold" 
          android:textColor="@android:color/black" 
          android:textAlignment="center" 
          android:layout_weight="2" 
          /> 
    
        </TableRow> 
        <TableRow 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:padding="2dp" android:layout_gravity="center"> 
         <RelativeLayout 
          xmlns:android="http://schemas.android.com/apk/res/android" 
          android:id="@+id/relativelayout" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:layout_weight="1"> 
    
          <ImageView 
           android:id="@+id/myImageView" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:src="@drawable/trframered1" 
    
           /> 
    
          <LinearLayout 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_alignLeft="@id/myImageView" 
           android:layout_alignTop="@id/myImageView" 
           android:layout_alignRight="@id/myImageView" 
           android:layout_alignBottom="@id/myImageView" 
           android:layout_margin="1dp" 
           android:gravity="center" 
           android:orientation="vertical" 
           > 
           <TextView 
            android:id="@+id/myImageViewTextHead" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_margin="1dp" 
            android:gravity="center" 
            android:text="@string/app_last_rank_grade" 
            android:textColor="#000000" /> 
           <TextView 
            android:id="@+id/txtLastDayRankGrade" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_margin="1dp" 
            android:gravity="center" 
            android:text="-" 
            android:textColor="#000000" /> 
    
          </LinearLayout> 
    
    
         </RelativeLayout> 
    
         <RelativeLayout 
          xmlns:android="http://schemas.android.com/apk/res/android" 
          android:id="@+id/relativelayout1" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" android:layout_gravity="center" android:gravity="center" android:layout_weight="1"> 
    
          <ImageView 
           android:id="@+id/myImageView1" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:src="@drawable/trframered1" /> 
    
          <LinearLayout 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_alignLeft="@id/myImageView1" 
           android:layout_alignTop="@id/myImageView1" 
           android:layout_alignRight="@id/myImageView1" 
           android:layout_alignBottom="@id/myImageView1" 
           android:layout_margin="1dp" 
           android:gravity="center" 
           android:orientation="vertical" 
           > 
           <TextView 
            android:id="@+id/myImageViewTextHead1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_margin="1dp" 
            android:gravity="center" 
            android:text="All Time" 
            android:textColor="#000000" /> 
           <TextView 
            android:id="@+id/txtLastAllTimeRankGrade" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_margin="1dp" 
            android:gravity="center" 
            android:text="-" 
            android:textColor="#000000" /> 
    
          </LinearLayout> 
    
    
         </RelativeLayout> 
        </TableRow> 
    </TableLayout> 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        > 
    
        <TableRow 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         android:padding="5dp"> 
         <Button 
          android:layout_height="wrap_content" 
          android:text="@string/app_get_questions" 
          android:id="@+id/btnNext" 
          android:textColor="@color/windowBackground" 
          android:layout_span="2" 
          android:layout_weight="2" 
          /> 
        </TableRow> 
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         > 
         <TextView 
          android:layout_height="wrap_content" 
          android:gravity="center_horizontal" 
          android:text="@string/app_scoring_leaders" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textStyle="bold" 
          android:layout_span="2" 
          android:layout_weight="2" 
          android:padding="5dp"/> 
        </TableRow> 
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         android:padding="5dp"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:id="@+id/txtDailyScores" 
          android:text="1. Kapil Bhagia (34511)\n2. Hardik Bhagia (2231)" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:layout_margin="5dp" 
          android:layout_weight="1"/> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:id="@+id/txtAllTimeScores" 
          android:text="1. Kapil Bhagia (34511)\n2. Hardik Bhagia (2231)" 
          android:textAppearance="?android:attr/textAppearanceSmall" 
          android:layout_margin="5dp" 
          android:layout_weight="1"/> 
        </TableRow> 
    
        <TableRow 
         android:layout_height="fill_parent" 
         android:layout_width="match_parent" 
         > 
         <TextView 
          android:layout_height="wrap_content" 
          android:gravity="center_horizontal" 
          android:text="@string/app_get_started" 
          android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textStyle="bold" 
          android:layout_weight="2" 
          android:layout_span="2" 
          android:padding="5dp"/> 
        </TableRow> 
        </TableLayout> 
    
          <LinearLayout 
           xmlns:android="http://schemas.android.com/apk/res/android" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:orientation="horizontal" > 
           <ImageView 
            android:layout_height="wrap_content" 
            android:src="@drawable/ic_assessment_black_36dp" 
            android:layout_gravity="center_vertical" 
            android:layout_width="wrap_content" 
            android:padding="10dp" 
            /> 
           <TextView 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:text="@string/app_intro" 
            android:textAppearance="?android:attr/textAppearanceSmall" 
            android:padding="10dp" 
            /> 
          </LinearLayout> 
    
          <LinearLayout 
           xmlns:android="http://schemas.android.com/apk/res/android" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:orientation="horizontal" > 
           <ImageView 
            android:layout_height="wrap_content" 
            android:layout_gravity="center_vertical" 
            android:src="@drawable/ic_today_black_36dp" 
            android:layout_width="wrap_content" 
            android:padding="10dp" 
            /> 
           <TextView 
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content" 
            android:textAppearance="?android:attr/textAppearanceSmall" 
            android:text="@string/app_base_score" 
            android:padding="10dp" 
            /> 
          </LinearLayout>