1

테이블 레이아웃의 최상위 행에는 layout_weight를 사용하여 3 개의 동등하게 분산 된 버튼이 있도록이 인터페이스를 만들었습니다. (내 생각이 길고 무관 ​​한 이후Android Layout_ TableLayout에서 제대로 작동하지 않습니까?

 <RelativeLayout 
      android:id="@+id/content_rel" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#ECECEC" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:id="@+id/blurImage" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 

       <TableLayout 
        android:id="@+id/tableLayout1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

        <TableRow 
         android:id="@+id/tableRow1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:padding="5dip" > 

         <ImageButton 
          android:id="@+id/btnHeartLike" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:clickable="true" 
          android:src="@drawable/selector" /> 

         <ImageButton 
          android:id="@+id/btnShare" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:clickable="true" 
          android:src="@drawable/share39" /> 

         <ImageButton 
          android:id="@+id/btnProductComment" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:clickable="true" 
          android:src="@drawable/comment_icon" /> 
        </TableRow> 

나는 코드의 나머지 부분을 추가하지 않은 :

enter image description here

그리고 이것은 내 코드입니다 :하지만이 내가 끝낼 무엇인가?). 나머지도 필요하면 알려주세요.하지만 문제는 레이아웃에 있다고 생각합니까? 뭐가 잘못됐다고 생각하니?

+1

상대 레이아웃에는 방향이 필요하지 않습니다. 선형 레이아웃 만 수직 또는 수평을 정의해야합니다. 또한 당신은 단지 3 개의 이미지 버튼을 사용하고 있기 때문에 왜 테이블 레이아웃을 사용하고 수평 선형 레이아웃을 사용하지 않고 layout_width = 1로 만들면 원하는 효과를 얻을 수 있습니다. –

+0

테이블 레이아웃을 사용하지 않으면 이미지 버튼이 도처에서 벗어 났고 완벽한 행이 아니라 내가 stackoverflow에 게시하지 않은 행이 더 많습니다. 내 선형 레이아웃을 수평으로 만드시겠습니까? 왜냐하면 저는 이미 수직 선형 레이아웃을 가지고 있습니다. @KostasMatrix –

+0

예. 아래 @ kamran 대답을보고 그의 대답에 가로 방향을 추가하십시오 –

답변

1

TableRow을 사용하는 이유 android:layout_width="0.0dip"

을 그리고을 확인 : 당신은

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

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

      <TableRow 

       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <Button 
        android:id="@+id/button1" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Button" /> 

       <Button 
        android:id="@+id/button2" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Button" /> 

       <Button 
        android:id="@+id/button3" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="Button" /> 
      </TableRow> 
     </TableLayout> 
    </LinearLayout> 
+0

아니 내가 테이블 레이아웃 선생님 필요 :) 거기에 다른 항목이 있고 내가 테이블 레이아웃을 사용하지 않으면 사방으로 난장판으로 옮기고있다. 테이블 레이아웃을 사용하고 이미지 버튼에 레이아웃 가중치를 사용하는 방법이 있습니까? –

+0

이것은 좋아 보이지만 같은 문제가 지속됩니다. (필자는 여러 행이 있기 때문에 생각합니다. –

0

대신 wrap_content있는의 0으로 폭을 설정해보십시오 linearlayout

다음 코드

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </LinearLayout> 

에게 다른 방법을 사용하여 사용하여 만들 수 있습니다 설명은 following link입니다.

관련 문제