2017-09-25 2 views
0

TableLayoutの修正点を分かち合いましょう。必要に応じてレイアウトを配置するための重みと列の設定方法を少し混乱させてください。私はlayout_spanに基づいてフォーマットの必要性を得ることを望んでいます。しかし、言葉で説明しようとします。見出しセンターが Android TableLayoutの問題 - 正しく設定できません。

  • 三行を揃え持っている - - 50%の面積を取って2 TextViewsを持つように幅
  • 第二行にまたがっボタンを持っている - 私は、レイアウト

    1. 最初の行を可視化する方法を下に置きます各
    2. 第4行 - 見出しの中心を整列させる
    3. 第5行 - 幅の16.6%を取る1つのImageViewと残りの83.3%を取るTextViewを持つこと。
    4. 6行目 - 1つのImageViewが幅の16.6%をとり、TextViewが残りの83.3%を占めるようにします。ここで

  • コードです:

    <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に関連する変更がある、テーブル全体の構造を変更しなければなりませんでした。私は最後の2行の代わりにLinearLayoutを使用しました。最初の4行は、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> 
    
    関連する問題