3

나는 RelativeLayout 내에 선형 여백을 가지고 화면의 가장 오른쪽에 정렬하려고합니다. 예 :여백을 사용하여 화면의 오른쪽에 정렬 안드로이드

enter image description here

어떻게 이것을 달성 할 수있는 LinearLayout의 속성을 수정해야합니까? 여기

감사

는 XML 파일 (오른쪽 정렬되어야있는 LinearLayout의 이름입니다 slide_right)입니다 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:gravity="top" 
    tools:context=".MainActivity" > 

    <WebView android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

    <LinearLayout 
     android:id="@+id/slide_left" 
     android:layout_width="400dp" 
     android:layout_height="550dp" 
     android:layout_marginLeft="-367dp" 
     android:layout_marginTop="150dp" 
     android:background="@drawable/left_slide" 
     android:orientation="vertical" > 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/slide_right" 
     android:layout_width="400dp" 
     android:layout_height="550dp" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="-30dp" 
     android:orientation="horizontal" 
     android:background="@drawable/right_slide"> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/header_linear_l" 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:orientation="horizontal" > 

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

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



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

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

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

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

       <ImageButton 
        android:id="@+id/lvlbt" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/levelbt" /> 
      </LinearLayout> 

      <ProgressBar 
       android:id="@+id/experiencebar" 
       style="?android:attr/progressBarStyleHorizontal" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

     </LinearLayout> 

    </LinearLayout> 

    <ImageButton 
     android:id="@+id/Attack_Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/slide_left" 
     android:layout_marginBottom="129dp" 
     android:layout_marginLeft="36dp" 
     android:layout_toRightOf="@+id/slide_left" 
     android:src="@drawable/ic_launcher_old" 
     android:visibility="invisible" /> 

</RelativeLayout> 
+0

XML 파일을 게시하십시오. –

+0

XML 파일을 게시 할 필요가 없습니다. 내 (Shridutt Kothari)의 답변을 참조하십시오. –

답변

10
당신의 Relative layout's Property

에서

android:layout_width="wrap_content" 

이 ...

enter image description here(도전적으로 내가 그것을 스냅 샷 아래를 참조 테스트 한)

android:layout_width="match_parent" 

그게 전부로 변경

+1

감사합니다. 현재 예상대로 작동하고 있습니다. 여기에 약속 upvote입니다 :) – astralmaster

+1

쿨 .. 좋은 사람들을 돕는. 이미지를 게시하고 빠른 답장을 보내기 위해 shridutt에게 +1하십시오. 나는 StackTrace를 사랑합니다. –

0

다음 코드 여기

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/your_relative_layout_id"   
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" > 

    <LinearLayout 
     android:id="@+id/your_linear_layout_id" 
     android:layout_width="50dip" 
     android:layout_height="50dip" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="-30dip" 
     android:background="#e42c2a" 
     android:orientation="horizontal" > 
    </LinearLayout> 

</RelativeLayout> 

android:layout_alignParentRight="true" 
android:layout_centerVertical="true" 
android:layout_marginRight="-30dip" 
를 참조하십시오

을 사용하십시오.

+0

같은,이 방법을 시도 - 안드로이드 : layout_marginRight 아무런 영향을 미치지 않습니다. 레이아웃 XML을 첫 번째 게시물에 포함합니다. – astralmaster

+0

위의 xml을 읽었을 때 상대방 레이아웃에 일치하는 부모 속성이 포함되어있어 솔루션에 충분했다고 생각합니다. 하지만 당신은 그것을 읽었을 것입니다 ... 그리고 나는 새로운 대답을 써야했습니다. 다시 당신을 위해 ..하지만 문제 없습니다. 제안 : 앞으로 pls 항상 전체 답변을 읽고 또한 신중하게. –

관련 문제