2013-08-01 5 views
10

다음은 나의 테이블 코드입니다. 내 화면은 http://imgur.com/dFP298o처럼 보이지만이 모양은 http://imgur.com/YuYJiJx처럼 보이게하고 싶습니다. 각 행과 테이블 레이아웃 주위에 테두리를 추가하려면 어떻게합니까? 테이블 행 주위와 테이블 레이아웃 주위에 테두리를 생성하기 위해TableLayout 주위에 테두리를 추가하는 방법은 무엇입니까?

<TableLayout 
    android:id="@+id/table2" 
    android:layout_width="fill_parent" 
    android:layout_below="@+id/test_button_text23" 
    android:layout_marginLeft="45dp" 
    android:layout_marginBottom="25dp" 
    android:layout_marginRight="45dp"  
    android:layout_height="fill_parent" 
    android:stretchColumns="*" > 

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

     <TextView 
      android:gravity="left" 
      android:text="Quantity" 
      android:textStyle="bold" /> 

     <TextView 
      android:gravity="center" 
      android:textStyle="bold" 
      android:text="Item" /> 

    </TableRow> 

</TableLayout>  

 

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:id="@+id/localTime" 
     android:textColor="#000000" 
     android:gravity="left" /> 

    <TextView 
     android:id="@+id/apprentTemp" 
     android:textColor="#000000" 
     android:gravity="center" /> 

</TableRow> 

 

View row = getLayoutInflater().inflate(R.layout.rows, null); 
((TextView) row.findViewById(R.id.localTime)).setText(item.getString("Item")); 
((TextView) row.findViewById(R.id.apprentTemp)).setText(item.getString("Quantity")); 
+1

이 다른 답변을 살펴보십시오. http://stackoverflow.com/a/7379990/2324810 – Hadriel

+0

내 코드를 편집하는 것이 너무 혼란 스럽습니다. – user2589245

답변

20

, 당신은 경계 역할을하는 드로어 블을 작성해야 행의 배경으로 설정하십시오. 예를 들어

:

고해상도/드로어 블/사진 border.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape= "rectangle"> 
    <solid android:color="#000000"/> 
    <stroke android:width="1dp" android:color="#000000"/> 
</shape> 

고해상도/레이아웃/your_layout.xml

<TableLayout 
    android:id="@+id/table2" 
    android:layout_width="fill_parent" 
    android:layout_below="@+id/test_button_text23" 
    android:layout_marginLeft="45dp" 
    android:layout_marginBottom="25dp" 
    android:layout_marginRight="45dp" 
    android:layout_height="fill_parent" 
    android:stretchColumns="*"> 

    <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/border"> 

      <TextView 
       android:gravity="left" 
       android:text="Quantity" 
       android:background="@drawable/border" 
       android:textStyle="bold"/> 

      <TextView 
       android:gravity="center" 
       android:textStyle="bold" 
       android:background="@drawable/border" 
       android:text="Item" /> 

    </TableRow> 

</TableLayout> 

이 정확히 같지 않습니다 당신이 올린 사진이지만, 당신이 원하는 것을 얻기 위해 그걸 가지고 놀아 라.

+5

<솔리드 android : color = "# ffffff"/ insted –

관련 문제