2011-03-16 3 views
5

을 맞 춥니 다. 안드로이드를 처음 접했을 때 나는해야 할 일에 대한 다른 단서가 없습니다. 내가 화면안드로이드 : 센터 나는 그것을 화면의 중앙에 제대로 정렬하기 위해 모든 노력을 한이</p> <p><img src="https://i.stack.imgur.com/cKEEb.png" alt="enter image description here"></p> <p>추천 ImageButons이 ImageButtons

의 중심이 2 Imagebuttons를 정렬 내 목표를 달성 할 수있는 방법이 내 레이아웃 XML 내가 직접이 버튼에 대한 이미지가 희망

<TableLayout android:id="@+id/TableLayout01" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:stretchColumns="1"> 
     <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

      <ImageButton android:id="@+id/btn_Show" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:text="Show" android:src="@drawable/cmd_result_show" 
       android:layout_gravity="right" android:background="@android:color/transparent" /> 

      <ImageButton android:id="@+id/btn_showAll" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:text="Detailed Show" android:layout_gravity="center" 
       android:src="@drawable/cmd_result_details" android:background="@android:color/transparent" /> 
     </TableRow> 
    </TableLayout> 
+0

당신을 위해 일한 의견을 추가하거나 문제가 있으시면 ... 올바른 대답을 수락하십시오. – Mathew

답변

6

입니다. 따라서이 설정 text 속성은 아무 소용이 없습니다. 이러한 종류의 화면을 쉽게 개발하려면 RelativeLayout을 사용하십시오.

아래 코드를 첨부했습니다. 어떤 문제가 있으면 보시고 코멘트를 추가하십시오.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:gravity="center_horizontal"> 

    <ImageButton android:id="@+id/btn_Show" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:background="@drawable/cmd_result_show" /> 

    <ImageButton android:id="@+id/btn_showAll" 
     android:layout_toRightOf="@id/btn_Show" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:background="@drawable/cmd_result_details" /> 
</RelativeLayout> 
+0

고마워요. 완벽하게 일했습니다. 그 사이에 공백을주기 위해 빈 TextView를 추가했습니다. 고마워요 –

+2

공간을 추가하려는 경우, 그 textview를 추가 할 필요가 없습니다 ... margin 속성을 추가하면 충분합니다. 처음부터 버튼을 안드로이드와 같은 줄 : layout_marginRight = "30dp"... 그것은 여백을 추가하므로 간격이 증가 할 것입니다 ... – Mathew

+0

thanks..it worked –

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:gravity="center"> 
    <TableLayout android:id="@+id/TableLayout01" 
    android:stretchColumns="1" android:layout_height="wrap_content" 
    android:layout_width="wrap_content" > 
    <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
     <ImageButton android:id="@+id/btn_Show" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:text="Show" android:src="@drawable/cmd_result_show" 
      android:layout_gravity="right" android:background="@android:color/transparent" /> 
     <ImageButton android:id="@+id/btn_showAll" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:text="Detailed Show" android:layout_gravity="center" 
      android:src="@drawable/cmd_result_details" android:background="@android:color/transparent" /> 
    </TableRow> 
</TableLayout> 

즐기!

0

tablerow 안에 ImageButton을 넣었습니다. tablerow는 항상 화면의 첫 번째 레이어를 차지합니다. 버튼을 가운데 정렬하고 상단 위치에 놓으시겠습니까?

관련 문제

 관련 문제