0

부모 LinearLayout 중심에서 TextView를 어떻게 수정합니까? 그리고 갭에있는 버튼은 TextView & 부모의 오른쪽 가장자리에 있습니다. (TextView는 중앙에 있어야합니다). 도와주세요.안드로이드 : LinearLayout 중심의 텍스트 뷰 수정

|--------------------------------------------------------| <------Parent Linearlayout 

|     MyTextviewInCenter   BackButton| <------There should not be any gap b/w Button & its parent 
|--------------------------------------------------------| 

답변

4
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"> 

     <TextView android:layout_centerInParent="true" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hello"/> 

     <Button android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Back" 
       android:layout_alignParentRight="true"/>  

    </RelativeLayout>> 


</LinearLayout> 

당신은 수평 선형 레이아웃의 방향 설정이

+0

고마워요. 그것은 작동합니다. Rel_Layout을 사용하지 않고도 동일한 작업을 수행 할 수 있습니까? – SANDHYA

+0

나는 다른 레이아웃을 시도했지만 나에게 도움이되지 못했다. –

+0

LinearLayout만으로는 불가능하다고 생각합니다. – Santhosh

0

같이 수행 할 수 있습니다

android:orientation="horizontal" 

그 텍스트 뷰의 중력을 설정 "센터"

android:layout_gravity="center" 

그리고 마지막으로 B의 왼쪽 여백을 설정합니다. utton 당신이 원하는 무엇을

android:layout_marginLeft="25dp" 

나는 그것이 당신을 도울지도 모른다라고 생각한다. .. !!!

관련 문제