2017-02-18 103 views
0

我有一個活動,承載一個片段和一個按鈕,該片段應占據屏幕的大部分,而按鈕應占據屏幕下半部分的一小部分。 但是,我不能使相對佈局收縮,使按鈕不重疊片段。相對佈局視圖不縮小在較小的屏幕上

下面

是我的活動佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_registration" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical" 
    tools:context="com.example.activities.RegistrationActivity"> 

    <fragment 
     android:name="com.example.fragments.registration.GenderFragment" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     tools:layout="@layout/fragment_gender" /> 

    <Button 
     android:id="@+id/profile_progress_bar" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:background="@color/colorPrimary" 
     android:text="BUTTON TEXT" 
     android:textColor="@android:color/holo_red_dark" /> 

</LinearLayout> 

及以下的片段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    tools:context="com.example.fragments.registration.GenderFragment"> 

    <ImageView 
     android:id="@+id/welcome_note" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:paddingTop="@dimen/xlarge_top_margin" 
     android:src="@drawable/bienvenido" /> 

    <TextView 
     android:id="@+id/gender_explanation" 
     style="@style/HeaderTitleWhite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/welcome_note" 
     android:layout_centerHorizontal="true" 
     android:text="WELCOME TO THE APP" 
     android:textSize="@dimen/header_title_text_view_xtra_big_size" /> 

    <LinearLayout 
     android:id="@+id/gender_avatar_holder" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/gender_explanation" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="@dimen/medium_top_margin" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/female" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/woman" 
      android:scaleType="centerInside" /> 


     <ImageView 
      android:id="@+id/male" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/man" 
      android:scaleType="centerInside" /> 

    </LinearLayout> 

    <Button 
     android:id="@+id/next" 
     style="@style/AppButtonMedium" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_alignEnd="@+id/gender_explanation" 
     android:layout_alignLeft="@+id/gender_explanation" 
     android:layout_alignRight="@+id/gender_explanation" 
     android:layout_alignStart="@+id/gender_explanation" 
     android:layout_below="@+id/gender_avatar_holder" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="@dimen/large_top_margin" 
     android:text="NEXT" 
     android:textStyle="normal|bold" /> 

</RelativeLayout> 
下面

的佈局是如何看起來

demo

回答

0

你frangment截圖內容太大,所以您應該在佈局中使用ScrollView , 喜歡這個。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 

android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<RelativeLayout xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    tools:context="com.example.fragments.registration.GenderFragment"> 

    <ImageView 
     android:id="@+id/welcome_note" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:paddingTop="@dimen/xlarge_top_margin" 
     android:src="@drawable/bienvenido" /> 

    <TextView 
     android:id="@+id/gender_explanation" 
     style="@style/HeaderTitleWhite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/welcome_note" 
     android:layout_centerHorizontal="true" 
     android:text="WELCOME TO THE APP" 
     android:textSize="@dimen/header_title_text_view_xtra_big_size" /> 

    <LinearLayout 
     android:id="@+id/gender_avatar_holder" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/gender_explanation" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="@dimen/medium_top_margin" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/female" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="centerInside" 
      android:src="@drawable/woman" /> 


     <ImageView 
      android:id="@+id/male" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="centerInside" 
      android:src="@drawable/man" /> 

    </LinearLayout> 

    <Button 
     android:id="@+id/next" 
     style="@style/AppButtonMedium" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_alignEnd="@+id/gender_explanation" 
     android:layout_alignLeft="@+id/gender_explanation" 
     android:layout_alignRight="@+id/gender_explanation" 
     android:layout_alignStart="@+id/gender_explanation" 
     android:layout_below="@+id/gender_avatar_holder" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="@dimen/large_top_margin" 
     android:text="NEXT" 
     android:textStyle="normal|bold" /> 

</RelativeLayout> 

+0

確定,但有沒有辦法讓沒有滾動視圖這項工作的方式,使相對佈局的內容縮小以適合? – Fouad

+0

@Fouad的方式是創建所有密度的佈局。 –

+0

你的意思是我應該爲不同的屏幕尺寸創建不同的佈局或使用dp和sp單位? – Fouad

相關問題