2015-01-07 3 views
0

enter image description hereTableLayout을 아래 내 활동 파일입니다, 나는뿐만 아니라 전체 화면의 테이블 레이아웃의 배경 이미지를 추가하는 화면의 중앙에있는 테이블 레이아웃을 보여주고 싶었다

화면의 중간에 그것을 보여주는, 어떻게해야하는지 알려주세요.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="1"> 

    <TableRow> 
     <TextView 
      android:text="User Name: " 
      android:id="@+id/TextView01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 

     <EditText 
      android:text="" 
      android:id="@+id/txtUname" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     </EditText> 
    </TableRow> 


    <TableRow> 
     <TextView 
      android:text="Password: " 
      android:id="@+id/TextView02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 


     <EditText 
      android:text="" 
      android:id="@+id/txtPwd" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:password="true"> 
     </EditText> 
    </TableRow> 


    <TableRow> 
     <Button 
      android:text="Cancel" 
      android:id="@+id/btnCancel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     </Button> 


     <Button 
      android:text="Login" 
      android:id="@+id/btnLogin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     </Button> 


    </TableRow> 


</TableLayout> 

감사합니다,

근무 코드 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/loginbackmain" 
    android:gravity="center"> 
    <ImageView android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/ic_launcher" 
     android:id="@+id/userDp"/> 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:gravity="center" 
     android:background="@drawable/loginformback" 
     android:stretchColumns="1"> 

     <TableRow> 
      <TextView 
       android:text="User Name: " 
       android:id="@+id/TextView01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 

      <EditText 
       android:text="" 
       android:id="@+id/txtUname" 
       android:layout_width="fill_parent" 
       android:paddingLeft="5dp" 
       android:layout_height="wrap_content"> 
      </EditText> 
     </TableRow> 


     <TableRow> 
      <TextView 
       android:text="Password: " 
       android:id="@+id/TextView02" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </TextView> 


      <EditText 
       android:text="" 
       android:id="@+id/txtPwd" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:password="true"> 
      </EditText> 
     </TableRow> 


     <TableRow> 
      <Button 
       android:text="Cancel" 
       android:id="@+id/btnCancel" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
      </Button> 


      <Button 
       android:text="Login" 
       android:id="@+id/btnLogin" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
      </Button> 


     </TableRow> 


    </TableLayout> 
    </LinearLayout> 
+0

코드를 선형 레이아웃에 넣으면됩니다. android : gravity = "center"를 linearlayout에 추가하고 TableLayout의 layout_height = "wrap_content"를 –

+0

부모 레이아웃 (TableLayout)에 안드로이드 : gravity = "center" – Dhina

+0

@Dhina android : 중력 = "center"to parent layout tablerow 중심으로 만들지 만 표 레이아웃에 대한 배경 이미지 만 만족시키지 않습니다. –

답변

2

나는이 당신이 원하는 것 같다. 오후 8시 30 분 P.S. 여백을 추가하여 EditTexts에 여백을 사용하는 것이 좋습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center"> 
<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:gravity="center" 
    android:background="#23f3AA" 
    android:stretchColumns="1"> 

    <TableRow> 
     <TextView 
      android:text="User Name: " 
      android:id="@+id/TextView01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 

     <EditText 
      android:text="" 
      android:id="@+id/txtUname" 
      android:layout_width="fill_parent" 
      android:paddingLeft="5dp" 
      android:layout_height="wrap_content"> 
     </EditText> 
    </TableRow> 


    <TableRow> 
     <TextView 
      android:text="Password: " 
      android:id="@+id/TextView02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 


     <EditText 
      android:text="" 
      android:id="@+id/txtPwd" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:password="true"> 
     </EditText> 
    </TableRow> 


    <TableRow> 
     <Button 
      android:text="Cancel" 
      android:id="@+id/btnCancel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     </Button> 


     <Button 
      android:text="Login" 
      android:id="@+id/btnLogin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     </Button> 


    </TableRow> 


</TableLayout> 

+0

고마워요, 내 XML에 추가 된 변경 사항에 따라 오랫동안 나는 http://stackoverflow.com/questions/27707649/creating-fragments-for-login 당보기를 얻으려고 노력하고 있지만 실패했습니다. 할 일 – sarah

+0

나는 조금 밖에 달성하지 못했던 테이블 레이아웃을 사용하고있다. – sarah

+0

@ sarah 나는 당신을 얻지 않았다. 당신은 더 도움이 필요합니까? 예, 그렇다면 나에게 이메일을 보내거나 이메일을 보내서 기꺼이 도와 드리겠습니다 :) ([email protected]) –

0
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="1" 
    android:layout_gravity="center" 
    android:background="@drawable/yourimagename"> 

이 나를 위해 일했다!

0

TableLayout의 경우 android : gravity = "true"