2012-07-10 14 views
11

मैं एक टेबल लेआउट प्रदर्शित कर रहा हूं, जिसमें मुझे तालिका में पंक्तियों के बीच अलगाव रेखा चाहिए। तालिका लेआउट में कॉलम वार पृथक्करण करना भी संभव है। कृपया मेरी मदद करें।तालिका लेआउट में पंक्तियों के बीच अलगाव

के बाद मेरी एक्सएमएल तालिका लेआउट है:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:paddingBottom="6dip" 
    android:paddingTop="4dip"> 

    <TableLayout 
     android:id="@+id/tablelayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingRight="2dip"> 

     <TableRow> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Income"></TextView> 

      <TextView 
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="150dp" 
       android:text="Expense"></TextView> 
     </TableRow> 

     <TableRow android:layout_marginTop="30px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Household:"></TextView> 

      <TextView 
       android:id="@+id/text50" 
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:text="Household:"></TextView> 
     </TableRow> 


     <TableRow android:layout_marginTop="40px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_span="2" 
       android:text="Travel:"></TextView> 

      <TextView 
       android:id="@+id/text51" 
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="-250dp" 
       android:text="Travel"></TextView> 
     </TableRow> 

     <TableRow android:layout_marginTop="40px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_span="2" 
       android:text="Education:"></TextView> 

      <TextView 
       android:id="@+id/text52" 
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="-250dp" 
       android:text="Education"></TextView> 
     </TableRow> 

    </TableLayout> 
</LinearLayout> 
+2

यू तालिका पंक्ति में 2 ग्रंथों, एक छवि (लाइन) पाठ होने चौड़ाई 2dp.this के बीच विभक्त विभक्त – AkashG

+0

रूप में काम करेंगे आप भी इस कोशिश कर सकते हैं के रूप में/दृश्य जोड़ने जोड़ रहे हैं के रूप में। http://stackoverflow.com/questions/2108456/how-can-i-create-a-table-with-borders-in-android या http://stackoverflow.com/questions/7117533/कैसे-से-देने-सीमा-के-कक्ष-इन-टेबललेआउट-इन-एंड्रॉइड – spr

उत्तर

25

इसे जांचें। यह काम करेगा।

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white" 
    android:orientation="vertical" 
    android:paddingBottom="6dip" 
    android:paddingTop="4dip" > 

    <TableLayout 
     android:id="@+id/tablelayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingRight="2dip" > 

     <TableRow> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Income" > 
      </TextView> 

      <TextView 
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="150dp" 
       android:text="Expense" > 
      </TextView> 
     </TableRow> 

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

      <View 
       android:id="@+id/line1" 
       android:layout_width="match_parent" 
       android:layout_height="1dip" 
       android:layout_weight="1" 
       android:background="#FF909090" 
       android:padding="2dip" /> 
     </TableRow> 

     <TableRow android:layout_marginTop="30px" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Household:" > 
      </TextView> 

      <TextView 
       android:id="@+id/text50" 
       android:layout_width="150px" 
       android:layout_height="wrap_content" 
       android:text="Household:" > 
      </TextView> 
     </TableRow> 
     </TableLayout> 

</LinearLayout> 
+0

क्या हम वही प्रोग्रामेटिक रूप से कर सकते हैं? क्योंकि मैं प्रोग्रामेटिक आधारित लेआउट बना रहा हूं। – AndroidOptimist

+2

मुझे लगता है कि यह करने का यह लिखने का तरीका नहीं है। यदि आपके पास 20 टेबल पंक्तियां हैं तो आपको विभाजक के लिए 20 पंक्तियां अधिक बनाना होगा ..... मुझे लगता है कि टेबललेआउट में "एंड्रॉइड: डेविडर" नामक टैग है .. लेकिन मुझे नहीं पता कि इसका उपयोग कैसे करें ... अगर कुछ शरीर जानता है कृपया जल्द ही बताएं ... –

+0

विभाजक विचारों में 'android: layout_span =" 2 "' जोड़ने के लिए मत भूलना। – Roel

4
View v = new View(this); 
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1)); 
v.setBackgroundColor(Color.rgb(51, 51, 51)); 
tr.addView(mTvDate); 
tr.addView(mTvResult); 

tl.addView(tr); 
tl.addView(v); 

from here.

+0

धन्यवाद विनय वाधवा..क्या आप कृपया मुझे बता सकते हैं कि मुझे यह कहां जोड़ना है ?? –

+0

प्रोग्रामैटिक – AkashG

+0

करने के बजाय अपने xml में दो टेक्स्टव्यू के बीच एक दृश्य जोड़ें, आप इस कोड को उस गतिविधि में जोड़ सकते हैं जो आपके प्रश्न में उल्लिखित XML का उपयोग करता है। –

1

मुझे लगता है कि आप TableLayout की पृष्ठभूमि और अपने पंक्तियों की मार्जिन के साथ खेलने के लिए है ...

+0

इस तरह मैंने यह भी किया, चींटी, यह सबसे अच्छा समाधान है क्योंकि यह लेआउट में ब्लोट को देखने से बचाता है। – olefevre

0

मैंने आपके कोड में कुछ बदलाव किए हैं और आपको लगता है कि यह आपकी मदद करेगा ...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:paddingTop="4dip" 
    android:paddingBottom="6dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical">  
<TableLayout 
    android:id="@+id/tablelayout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:paddingRight="2dip"> 

    <TableRow > 
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Income"> 
    </TextView>    
     <TextView    
      android:layout_width="150px" android:layout_height="wrap_content" android:text="Expense" android:layout_marginLeft="150dp"> 
    </TextView> 
    </TableRow> 
<View android:id="@+id/firstDivider" 
     android:layout_height="2dp" 
     android:layout_width="fill_parent" 
     android:background="#FFFFFF" /> 


    <TableRow android:layout_marginTop="30px"> 
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Household:" > 
    </TextView>    
     <TextView    
      android:id="@+id/text50" android:layout_width="150px" android:layout_height="wrap_content" android:text="Household:"> 
    </TextView> 
    </TableRow> 
<View android:id="@+id/firstDivider" 
     android:layout_height="2dp" 
     android:layout_width="fill_parent" 
     android:background="#FFFFFF" /> 



<TableRow android:layout_marginTop="40px"> 
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Travel:" android:layout_span="2"> 
    </TextView>  
     <TextView 
      android:id="@+id/text51" 
      android:layout_width="150px" android:layout_height="wrap_content" android:text="Travel" android:layout_marginLeft="-250dp"> 
    </TextView> 


</TableRow> 


<View android:id="@+id/firstDivider" 
     android:layout_height="2dp" 
     android:layout_width="fill_parent" 
     android:background="#FFFFFF" /> 

    <TableRow android:layout_marginTop="40px"> 
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Education:" android:layout_span="2"> 
    </TextView>  
     <TextView 
      android:id="@+id/text52" 
      android:layout_width="150px" android:layout_height="wrap_content" android:text="Education" android:layout_marginLeft="-250dp"> 
    </TextView> 

</TableRow> 

<View android:id="@+id/firstDivider" 
     android:layout_height="2dp" 
     android:layout_width="fill_parent" 
     android:background="#FFFFFF" /> 


</TableLayout> 
</LinearLayout> 

धन्यवाद ....

+0

धन्यवाद उपयोगकर्ता 4232..लेकिन कुछ भी नहीं आ रहा है..टेबल लेआउट गिर रहा है .. –

3

TableLayoutLinearLayout ताकि आप एक्सएमएल में विभाजक जोड़ सकते हैं प्रदान करता है।

<TableLayout 
     android:id="@+id/basket_summary_table" 
     android:showDividers="middle" 
     android:divider="@drawable/divider_list" 
     android:padding="@dimen/element_large_spacing" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="0"> 
    </TableLayout> 

मेरे विभक्त ऐसा दिखाई देता है:: मैं इस वक्त काम करेगा मान

divider_list.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <size android:height="1dp" /> 
    <solid android:color="@color/list_divider" /> 
</shape> 
10

आप उसके बाद ही पंक्तियों के बीच एक विभक्त जोड़ने के लिए TableRow division चाहते हैं एक अच्छा समाधान है।

<TableLayout  
    android:divider="?android:attr/dividerHorizontal" 
    android:showDividers="middle" 
    ... 
+0

Thnx ... शानदार समाधान .. आकर्षण की तरह काम ... !! –

संबंधित मुद्दे