2010-08-04 2 views
0

모서리가 둥근 테이블을 만들려고합니다. 이 작업을 수행하는 데는 꽤 많은 XML이 있지만 문제가 있습니다. 테이블 자체가 내부 텍스트의 너비로 감싸고 있습니다. 나는 부모님을 채우기 위해 모든 것을 원한다. (나는 주변에 경계선이 있기 때문에 내가 가지고있는 쿠션이있다.) 나는 fill_parent에 모든 것이있을 때 왜 그것이 아닌지 이해할 수 없다. 누군가 잘못 된 것을 지적 할 수 있습니까?일부 고급 UI에서 문제가 발생했습니다.

screenshot 1

shape_outer.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#0000FF"/> 
    <corners android:radius="5px"/> 
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape> 

shape_inner.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <corners android:radius="5px"/> 
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape> 

내 레이아웃 : 여기

무슨 뜻인지의 스크린 샷과 내 XML의 사본입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="47px" 
     style="?android:attr/windowTitleBackgroundStyle" 
     android:gravity="center"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="My title" 
      style="?android:attr/windowTitleStyle" 
      android:paddingLeft="5px" /> 
    </LinearLayout> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:padding="10px" 
     > 
     <!-- used so we can separate two tables --> 
     <TableLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:stretchColumns="1" 
      > 
      <!-- first table --> 
      <TableRow android:paddingBottom="10px"> 
       <!-- outer border --> 
       <TableLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:stretchColumns="1" 
        android:padding="2px" 
        android:background="@drawable/shape_outer" 
        > 
        <TableRow> 
         <!-- inner whitespace --> 
         <TableLayout 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:stretchColumns="1" 
          android:layout_weight="1" 
          android:background="@drawable/shape_inner" 
          android:padding="10px" 
          > 
          <TableRow> 
           <!-- first row: one --> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="One:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/one" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="sadflkjaasasdfadsdsf;lkjdsal;asdj" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:maxLines="1" /> 
           </LinearLayout> 
          </TableRow> 
          <!-- separator --> 
          <View 
           android:layout_height="1dip" 
           android:background="#FF909090" /> 
          <TableRow> 
           <!-- second row: two --> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="Two:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/two" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="asdfasdasdfasdfasfasdfasgeargfsgsfd" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:maxLines="1" /> 
           </LinearLayout> 
          </TableRow> 
         </TableLayout> 
        </TableRow> 
       </TableLayout> 
      </TableRow> 
      <!-- second table --> 
      <TableRow> 
       <!-- outer border --> 
       <TableLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:stretchColumns="1" 
        android:padding="2px" 
        android:background="@drawable/shape_outer" 
        > 
        <TableRow> 
         <!-- inner white space --> 
         <TableLayout 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:stretchColumns="1" 
          android:background="@drawable/shape_inner" 
          android:padding="10px" 
          > 
          <!-- third row: Three --> 
          <TableRow> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="Three:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/three" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="asdfasfasdfasgeargfsgsfd" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:singleLine="true" 
             android:ellipsize="end" /> 
           </LinearLayout> 
          </TableRow> 
          <!-- separator --> 
          <View 
           android:layout_height="1dip" 
           android:background="#FF909090" /> 
          <!-- second row: four --> 
          <TableRow> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:gravity="left|center_vertical" 
            > 
            <TextView 
             android:layout_width="70px" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="Four:" 
             android:padding="6dip" 
             android:textColor="#000000" /> 
            <TextView 
             android:id="@+id/four" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             android:layout_column="1" 
             android:text="aasdfasfasdfasgeargfsgsfd" 
             android:padding="6dip" 
             android:textColor="#000000" 
             android:singleLine="true" 
             android:ellipsize="end" /> 
           </LinearLayout> 
          </TableRow> 
         </TableLayout> 
        </TableRow> 
       </TableLayout> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 
</LinearLayout> 
+0

정말 복잡한 레이아웃처럼 보입니다. 도구 폴더에있는 HeirarchyViewer가 디버그하는 데 도움이 될 수 있습니다. 어떤 요소가 행을 원하는 위치 이상으로 늘리는 지 확인할 수 있습니다. –

+0

답장을 보내 주셔서 감사합니다. 테이블을 화면의 한계를 넘어서 확장시키는 것만이 아닙니다. 텍스트가 매우 짧으면 표가 매우 좁기 때문입니다. 하지만 아무것도 포장해야합니다 : ( – Andrew

+0

왜 그것을 이해하지 못하는 것 같아요. 왜 내 바깥 쪽 TableLayout 이제 fill_parent, 모든 다른 Table_Layout wrap_content 동안. – Andrew

답변

0

테이블 사용은 복잡하고 무의미했습니다. 여기 내 작업 XML은 다음과 같습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="10dip" 
    android:paddingBottom="10dip" 
    android:paddingLeft="15dip" 
    android:paddingRight="15dip" 
    > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="2dip" 
     android:background="@drawable/shape_outer" 
     > 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/shape_inner" 
      > 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="left|center_vertical" 
       android:padding="10dip" 
       > 
       <TextView 
        android:layout_width="70dip" 
        android:layout_height="wrap_content" 
        android:text="One:" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:gravity="right" /> 
       <TextView 
        android:id="@+id/one" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:text="sdklafjalfkjaslgkjafds" 
        android:maxLines="1" 
        android:ellipsize="end" /> 
      </LinearLayout> 
      <View 
       android:layout_height="1dip" 
       android:layout_width="fill_parent" 
       android:background="#FF909090" 
       android:padding="10dip" /> 
      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="left|center_vertical" 
       android:padding="10dip" 
       > 
       <TextView 
        android:layout_width="70dip" 
        android:layout_height="wrap_content" 
        android:text="Two:" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:gravity="right" /> 
       <TextView 
        android:id="@+id/two" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="6dip" 
        android:textColor="#000000" 
        android:text="dsaklfajsdkldsafjsf" 
        android:maxLines="1" 
        android:ellipsize="end" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
1

당신이 고칠 수있어서 기뻤지만, 상대적 레이아웃을 사용하면 훨씬 쉽게 동일한 모양을 완성 할 수 있습니다.

+0

어떻게 그렇게합니까? 나는 모양과 textviews를 서로 위에 위치시켜야합니다. 이것은 더 복잡한 수준이 아니겠습니까? – Andrew

+0

여기에 정말 어려운 부분이 있습니다. 이러한 테이블을 동적 싶습니다. 의미, 내 Java 코드에서 N 것들을 추가 할 수 싶습니다. 이것을 달성 할 수 있습니까? 내가 생각할 수있는 유일한 것은 ListView 하나를 사용하는 것입니다. 이 테이블의 목록 항목으로. 문제는 또한 테이블을 최대 2 행에서 싶지 않아요. 그 행뿐만 아니라 동적 수 싶습니다. – Andrew