2012-04-09 24 views
9

Tôi muốn tạo một bảng có ngăn chia cột. Tôi muốn chia các cột của tôi với một hình ảnh thanh dọc. Để đạt được điều này tôi đã sử dụng "android:divider="@drawable/abc" nhưng nó không hoạt động. Dưới đây là tập tin xml của tôi cho cùng:Cách đặt dải phân cách giữa các cột trong tablelayout?

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:stretchColumns="*" 
    android:padding="5dip" 
android:divider="@drawable/tracking_green" 
> 
<TableRow > 

<TextView 
    android:id="@+id/retaileritem1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:text="xxxxxxx" /> 

<TextView 
    android:id="@+id/retaileritem2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:text="xxxxxxx" /> 

<ImageView 
    android:id="@+id/retailerimage1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:src="@drawable/tracking_green" /> 

</TableRow> 

Trả lời

0

từ TableLayout không cung cấp này trực tiếp, một cách posibble có thể là một framelayout. đặt bảng mong muốn phía trên một background_table khác chỉ có một hàng và "match_parent" cho chiều cao/chiều rộng. thêm 3 cột với layout_weights mong muốn. thêm chế độ xem hình ảnh chia dọc vào cột thứ hai. bảng chính cũng nên sử dụng cùng một layout_weihts + lề trong hàng của hàng để trông tốt.

Dải phân cách ngang có thể được thực hiện bằng cách thêm một lần xem hình ảnh giữa các tabler "được phân tách".

chưa được thử nghiệm nào, chỉ là một cách tiếp cận

ornay

10

Thêm android: showDividers = "middle"

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:stretchColumns="*" 
    android:padding="5dip" 
    android:divider="@drawable/tracking_green" 
    android:showDividers="middle" 
> 
+0

cũng có cách nào để thay đổi màu sắc của dải phân cách không? –

+0

Ví dụ: Nếu bạn sử dụng --- android: divider = "@ color/orangeBackground" Sau đó, bạn có thể xác định giá trị tại colors.xml như --- ​​# FF8000

0

Trong một danh sách với một gốc cây thẳng đứng sử dụng ImageView như sau:

<ImageView 
    android:id="@+id/divider" 
    android:contentDescription="@string/divider" 
    android:layout_width="1dp" 
    android:layout_height="65dp" 
    android:layout_marginTop="8sp" 
    android:background="#3B3B3B" 
    /> 

Để tránh hiển thị dải phân cách khi không có yếu tố nào trong danh sách bạn có thể xóa e dòng android:background="#3B3B3B" và đặt nó cách lập trình:

1

gì tôi muốn là một bảng như thế này

table image with vertical dividers

tôi thêm này trong styles.xml tôi

<style name="Divider"> 
     <item name="android:layout_width">1dip</item> 
     <item name="android:layout_height">match_parent</item> 
     <item name="android:background">@color/divider_color</item> 
    </style> 

    <style name="Divider_invisible"> 
     <item name="android:layout_width">1dip</item> 
     <item name="android:layout_height">match_parent</item> 
    </style> 

Then in my table layout 

<TableLayout 
      android:id="@+id/table" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:stretchColumns="*" > 

      <TableRow 
       android:id="@+id/tableRow1" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:background="#92C94A" > 

       <TextView 
        android:id="@+id/textView11" 
        android:paddingBottom="10dp" 
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        android:paddingTop="10dp" /> 

       <LinearLayout 
        android:layout_width="1dp" 
        android:layout_height="match_parent" > 

        <View style="@style/Divider_invisible" /> 
       </LinearLayout> 

       <TextView 
        android:id="@+id/textView12" 
        android:paddingBottom="10dp" 
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        android:paddingTop="10dp" 
        android:text="@string/main_wo_colon" 
        android:textColor="@color/white" 
        android:textSize="16sp" /> 

       <LinearLayout 
        android:layout_width="1dp" 
        android:layout_height="match_parent" > 

        <View style="@style/Divider" /> 
       </LinearLayout> 

       <TextView 
        android:id="@+id/textView13" 
        android:paddingBottom="10dp" 
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        android:paddingTop="10dp" 
        android:text="@string/side_wo_colon" 
        android:textColor="@color/white" 
        android:textSize="16sp" /> 

       <LinearLayout 
        android:layout_width="1dp" 
        android:layout_height="match_parent" > 

        <View style="@style/Divider" /> 
       </LinearLayout> 

       <TextView 
        android:id="@+id/textView14" 
        android:paddingBottom="10dp" 
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        android:paddingTop="10dp" 
        android:text="@string/total" 
        android:textColor="@color/white" 
        android:textSize="16sp" /> 
      </TableRow> 

      <!-- display this button in 3rd column via layout_column(zero based) --> 

      <TableRow 
       android:id="@+id/tableRow2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#6F9C33" > 

       <TextView 
        android:id="@+id/textView21" 
        android:padding="5dp" 
        android:text="@string/servings" 
        android:textColor="@color/white" 
        android:textSize="16sp" /> 

       <LinearLayout 
        android:layout_width="1dp" 
        android:layout_height="match_parent" > 

        <View style="@style/Divider" /> 
       </LinearLayout> 

.......... 
....... 
...... 
2

Đây là làm thế nào tôi đã làm nó!

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="5dp" > 

       <TextView 
        android:id="@+id/textView4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="1" 
        android:paddingBottom="50dp" 
        android:text="Salary Details" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:textStyle="bold" /> 

       <TableLayout 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:shrinkColumns="0" 
        android:stretchColumns="1" > 

        <TableRow 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_gravity="center_vertical" > 

         <TextView 
          android:layout_gravity="center_vertical" 
          android:gravity="left" 
          android:text="Financial Year" 
          android:textColor="@android:color/white" 
          android:textSize="14sp" 
          android:textStyle="bold" /> 

         <Spinner 
          android:id="@+id/spnSearchByCity" 
          android:layout_width="fill_parent" 
          android:layout_height="40dp" 
          android:layout_gravity="center_vertical" 
          android:entries="@array/year" 
          tools:listitem="@android:layout/simple_spinner_dropdown_item" /> 
        </TableRow> 
       </TableLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="#d30059" 
        android:orientation="vertical" 
        android:paddingTop="50dp" > 

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

         <TableRow 
          android:id="@+id/tableRow1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@android:color/white" > 

          <TextView 
           android:id="@+id/textView1" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_marginTop="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="Month" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 

          <TextView 
           android:id="@+id/textView2" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_marginTop="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="Net Salary" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 

          <TextView 
           android:id="@+id/textView3" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_marginRight="1dp" 
           android:layout_marginTop="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="Click" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 
         </TableRow> 

         <TableRow 
          android:id="@+id/tableRow2" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@android:color/white" > 

          <TextView 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="Jan" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 

          <TextView 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="11305" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 

          <LinearLayout 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_marginRight="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:orientation="vertical" > 

           <TextView 
            android:id="@+id/txtDetailsOneId" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" 
            android:background="#000000" 
            android:text="DETAILS" 
            android:textAppearance="?android:attr/textAppearanceMedium" /> 
          </LinearLayout> 
         </TableRow> 

         <TableRow 
          android:id="@+id/tableRow3" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@android:color/white" > 

          <TextView 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="Feb" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 

          <TextView 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:text="11405" 
           android:textAppearance="?android:attr/textAppearanceMedium" /> 

          <LinearLayout 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:layout_marginBottom="1dp" 
           android:layout_marginLeft="1dp" 
           android:layout_marginRight="1dp" 
           android:layout_weight="1" 
           android:background="#d30059" 
           android:gravity="center" 
           android:orientation="vertical" > 

           <TextView 
            android:id="@+id/txtDetailsTwoId" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" 
            android:background="#000000" 
            android:text="DETAILS" 
            android:textAppearance="?android:attr/textAppearanceMedium" /> 
          </LinearLayout> 
         </TableRow> 

         <TableRow 
          android:id="@+id/tableRow4" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" > 
         </TableRow> 
        </TableLayout> 
       </LinearLayout> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="50dp" > 

       <Button 
        android:id="@+id/btnMainMenuId" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginTop="5dp" 
        android:text="MAIN MENU" 
        android:textColor="@android:color/white" 
        android:textSize="12sp" /> 
      </LinearLayout> 
     </LinearLayout> 

Snapshot

enter image description here

0

cố gắng thiết lập các TextView thứ hai marginleft = 1dp. nếu bạn không muốn thiết lập dải phân cách marginleft = 0dp

Các vấn đề liên quan