2017-06-24 9 views
0

私はAndroidでテーブルを作成しようとしています。 私は本当に遠いですが、私はHeadLineSumとBodySumに問題があります。 私は本当に欲しいものを表示するためにExcelのレイアウトを作った。テーブルテキストは右に整列します

enter image description here

そして、これは私が作成するために管理しているものです。 enter image description here

私のAndroidのレイアウトコード:

<!-- Breakfast --> 
     <TableLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <TableRow 
       android:id="@+id/tableRowHeadlineBreakfast" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/imageViewAddBreakfast" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        app:srcCompat="@drawable/ic_menu_add" /> 

       <TextView 
        android:id="@+id/textViewHeadlineBreakfast" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="80" 
        android:text="@string/breakfast" 
        android:textSize="18sp" /> 

       <TextView 
        android:id="@+id/textViewEnergyBreakfast" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:layout_weight="10" 
        android:text="@string/energy" 
        android:textSize="18sp" /> 
      </TableRow> 
     </TableLayout> 
    <TableLayout 
     android:id="@+id/tableLayoutBreakfastItems" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TableRow 
      android:id="@+id/tableRowBreakfastItems" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:id="@+id/textViewBreakfastItemsName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="80" 
       android:text="@string/name" 
       android:textSize="18sp" /> 

      <TextView 
       android:id="@+id/textViewBreakfastItemsEnergy" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_weight="10" 
       android:text="@string/energy" 
       android:textSize="18sp" /> 
     </TableRow> 

     <TableRow 
      android:id="@+id/tableRowBreakfastItemsSub" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:id="@+id/textViewBreakfastItemsSub" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/name" /> 

     </TableRow> 

    </TableLayout> 
    <!-- //Breakfast --> 

答えて

1

表のレイアウトは、あなたが同じのためのLinearLayoutを使用する必要がありますこのタイプの設計を達成するためにあまりにも古い技術です。

したい場合は、まだここに私のコード

最初に描画可能なフォルダにしてborder.xmlファイルを作成している私のコード

を貼り付けTableLayoutだけコピーを使用して、このタイプの設計を実現

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 

    <stroke android:width="1dp" android:color="#fff" /> 

</shape> 

コピー貼りthi Sコードmain_activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_table_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary" 
    android:orientation="vertical" 
    tools:context="com.example.dhruv.demovolleyjson.TableLayout"> 


    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <ImageView 
       android:layout_width="40dp" 
       android:layout_height="40dp" 

       android:background="@drawable/border" 
       android:padding="5dp" 
       android:src="@mipmap/ic_launcher" /> 

      <TextView 
       android:id="@+id/textViewHeadlineBreakfast" 
       android:layout_width="match_parent" 

       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:gravity="center_vertical" 
       android:padding="5dp" 
       android:text="Breakfast" 
       android:textColor="#fff" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 

       android:layout_gravity="right" 
       android:background="@drawable/border" 
       android:gravity="center" 
       android:padding="5dp" 
       android:text="Energy" 
       android:textColor="#fff" 
       android:textSize="20sp" /> 

     </TableRow> 

    </TableLayout> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="40dp"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 

       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:gravity="center_vertical" 
       android:padding="5dp" 
       android:text="Name" 
       android:textColor="#fff" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 

       android:layout_gravity="right" 
       android:background="@drawable/border" 
       android:gravity="center" 
       android:padding="5dp" 
       android:text="Energy" 
       android:textColor="#fff" 
       android:textSize="20sp" /> 
     </TableRow> 
    </TableLayout> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="40dp"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="40dp" 
       android:background="@drawable/border" 
       android:gravity="center_vertical" 
       android:padding="5dp" 
       android:text="Name" 
       android:textColor="#fff" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_gravity="right" 
       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:gravity="center" 
       android:padding="5dp" 
       android:textColor="#fff" 
       android:textSize="20sp" /> 
     </TableRow> 
    </TableLayout> 


</LinearLayout> 

enter image description here

+0

ありがとうございました。私はLinearLayoutでそれを行う方法を学ぶことにも興味があります。 – Solo

+0

ようこそ。 –

関連する問題