2017-05-18 1 views
0

나는 안드로이드를 처음 접했고, 모든 씬이 자신의 공간에 집중되어있는 이런 식으로하고 싶습니다.Android : 상대적 레이아웃 센터 자신의 공간에있는 것들

representative image

이 코드를했습니다

... 나는 그것을 바꿀 수있는 방법, 그 이유는 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="15dp" 
    tools:context="se.avatarcontrol.MainActivity"> 

    <TextView 
     android:id="@+id/weather" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/light" 
     android:layout_marginTop="15dp" 
     android:text="RAINY" /> 

    <Button 
     android:id="@+id/light" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:text="Light OFF" /> 

    <TextView 
     android:id="@+id/frontText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/sideText" 
     android:text="FrontView"/> 

    <TextView 
     android:id="@+id/sideText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/light" 
     android:layout_marginTop="15dp" 
     android:layout_alignParentRight="true" 
     android:text="SideView" /> 


    <ImageView 
     android:id="@+id/frontImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android: android:layout_below="@id/frontText" 
     android:src="**somesource**" /> 

    <ImageView 
     android:id="@+id/sideImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/sideText" 
     android:layout_alignParentRight="true" 
     android:src="**othersource**"/> 

</RelativeLayout> 

또 다른 것은 내 ImageViews이 서로 중첩 whithout 모든 공간을 채울 수있는 방법이 될 것입니다?

+0

질문 제목을 좀 더 구체적으로 작성하십시오. 이 제목은 당신이 downhotes을 얻을 것이다 – Nabin

+0

당신은 제약 레이아웃해야합니다, 이것은 구글이 레이아웃의 불필요한 중첩을 방지하기 위해 무엇을 제안합니다. –

답변

0

FrameLayout 또는 LinearLayout은 RelativeLayout보다 가볍기 때문에 사용하십시오.

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

<!-- Weather light Layout--> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="3"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:src="@mipmap/ic_launcher_round" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Light" /> 

</LinearLayout> 

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

    <!-- Front + Image Layout--> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Front" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Image" /> 

    </LinearLayout> 

    <!-- Side + Image Layout--> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Side" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Image" /> 


    </LinearLayout> 


</LinearLayout> 


</LinearLayout> 

이것은 구조 :

당신이 그런 짓을한다, 당신이 원하는 것을 달성하기 위해. 패딩/여백/ID와 layout_height 및 width를 조정하면됩니다. 귀하의 경우, 나는 여러보기 사이의 크기 비율을 지정하는 데 유용한 layout_weight를 사용했습니다.

+0

감사합니다! 선형 레이아웃으로 실제로 매우 쉬웠다 – Gohan

+0

@ Gohan14 당신이 내 도움을 주면 올바른 대답으로 표시해주세요 :) – Fcps

관련 문제