2017-04-12 2 views
0

내 XML에서이 작업을 수행하려고합니다. 현재 내가이 일을 해요 : 나는 단지 @drawable/logo의 일부를 얻을가로 세로 비율을 그대로 유지하면서 모든 화면에 맞도록 다른 요소간에 이미지 배치

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.MainActivity"> 
    <ImageView 
     android:id="@+id/main_drawable_text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:src="@drawable/text" /> 
    <LinearLayout 
     android:id="@+id/main_drawable_logo" 
     android:layout_width="match_parent" 
     android:layout_below="@id/main_drawable_text" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.1" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" 
      android:src="@drawable/logo" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_below="@id/main_drawable_logo" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/credits" 
      android:layout_width="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_height="wrap_content" 
      android:text="@string/credits" /> 
    </LinearLayout> 
</RelativeLayout> 

을 내 테스트 장치에서, 나머지는 신용의 텍스트처럼 화면에서 떨어진다. 원하는 결과가 나올 때까지 무게를 조정할 수는 있지만 모든 장치에서 예상되는 결과를 얻으려면 어떻게해야합니까?

내가 원하는 main_drawable_text 항상 화면 drawable_logo의 바닥에있는 항상 credits, (마진 마진에서) 화면의 폭을 일치 그들 사이의 여유 공간에 맞게 크기가 조정되어, 아직 원래의 화면 비율입니다 .

답변

1

내가 잘 UI를 이해하는 경우 (등등 android:layout_above, android:layout_below와 함께) 당신이 LinearLayoutRelativeLayout 기존 필요하지 않으며, 그 안에 당신이 서로의 위치에 따라 요소를 배치 할 수 있습니다 설계합니다. drawable의 원래 비율을 유지하려면 android:scaleType="fitCenter"을 사용하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin"> 

    <ImageView 
     android:id="@+id/main_drawable_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:src="@drawable/text"/> 

    <ImageView 
     android:id="@+id/logo" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_above="@id/credits" 
     android:layout_below="@id/main_drawable_text" 
     android:layout_centerHorizontal="true" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:src="@drawable/logo"/> 

    <TextView 
     android:id="@+id/credits" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="@string/credits"/> 

</RelativeLayout> 
: 여기

는 레이아웃 디스플레이 (내 해석) 당신이 원하는이다
관련 문제