2017-08-01 218 views
0

在代碼中,我只給出了dp中圖像的高度和寬度。但屏幕的整個內容仍以較低的屏幕尺寸離開屏幕。我已經在仿真器和真實設備上測試過它在5.5英寸屏幕中看起來不錯並且在其他屏幕尺寸上看起來不太好。RelativeLayout內容超出屏幕尺寸

請在下面找到下面的代碼。 郵件XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="reminder.locrem.com.locationreminder.AddLocationReminder"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@android:color/holo_blue_dark" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_add_location_reminder" /> 



</android.support.design.widget.CoordinatorLayout> 

內容的XML文件

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_add_location_reminder" 
    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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="reminder.locrem.com.locationreminder.AddLocationReminder" 
    tools:showIn="@layout/activity_add_location_reminder"> 


    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/ic_menu_camera" 
     android:id="@+id/addImage" 
     android:background="@android:drawable/screen_background_light_transparent" 
     android:layout_alignTop="@+id/textView3" 
     android:layout_alignParentEnd="true" 
     android:elevation="0dp" 
     android:onClick="launchChooseImageDialog"/> 

    <ImageView 
     android:layout_width="300dp" 
     android:layout_height="250dp" 
     app:srcCompat="@android:drawable/ic_menu_gallery" 
     android:layout_below="@+id/textView3" 
     android:layout_alignParentStart="true" 
     android:layout_marginStart="24dp" 
     android:layout_marginTop="15dp" 
     android:id="@+id/setImage" 
     android:layout_toStartOf="@+id/addImage" /> 

    <TextView 
     android:text="Add Items" 
     android:layout_width="wrap_content" 
     android:id="@+id/textView5" 
     android:layout_height="wrap_content" 
     android:textSize="24sp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textPersonName" 
     android:ems="10" 
     android:id="@+id/addItemsLaunchTextBox" 
     style="@style/Widget.AppCompat.AutoCompleteTextView" 
     android:selectAllOnFocus="true" 
     android:hint="Add Items" 
     android:onClick="launchAddItemsActivity" 
     android:layout_below="@+id/textView5" 
     android:layout_alignParentStart="true" 
     android:focusable="false"/> 

    <TextView 
     android:text="Select Place" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView7" 
     android:textSize="24sp" 
     android:layout_below="@+id/addItemsLaunchTextBox" 
     android:layout_alignParentStart="true" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textPersonName" 
     android:ems="10" 
     android:id="@+id/selectPlaceEditText" 
     android:hint="Choose Place" 
     android:onClick="launchChooseLocationActivity" 
     android:layout_below="@+id/textView7" 
     android:layout_alignParentStart="true" 
     android:focusable="false"/> 

    <TextView 
     android:text="Choose Image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/textView3" 
     android:textSize="24sp" 
     android:layout_below="@+id/selectPlaceEditText" 
     android:layout_alignParentStart="true" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/setImage" 
     android:id="@+id/add_reminder" 
     android:layout_centerHorizontal="true" 
     android:background="@color/cast_libraries_material_featurehighlight_outer_highlight_default_color" 
     android:text="Add" 
     android:textColor="@color/cardview_light_background" 
     android:textStyle="normal|bold" 
     android:elevation="11dp" 
     android:onClick="saveLocationReminder"/> 


</RelativeLayout> 

請找到參考

4英寸的屏幕 4 inch screen

4.7英寸的屏幕 4.7 inch screen

截圖

5.5英寸的屏幕 5.5 inch screen

回答

0

試試這個佈局,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/content_add_location_reminder" 
       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" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    > 


    <ImageButton 
     android:id="@+id/addImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignTop="@+id/textView3" 
     android:background="@android:drawable/screen_background_light_transparent" 
     android:elevation="0dp" 
     android:onClick="launchChooseImageDialog" 
     app:srcCompat="@drawable/ic_menu_camera"/> 



    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:text="Add Items" 
     android:textSize="24sp"/> 

    <EditText 
     android:id="@+id/addItemsLaunchTextBox" 
     style="@style/Widget.AppCompat.AutoCompleteTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView5" 
     android:ems="10" 
     android:focusable="false" 
     android:hint="Add Items" 
     android:inputType="textPersonName" 
     android:onClick="launchAddItemsActivity" 
     android:selectAllOnFocus="true"/> 

    <TextView 
     android:id="@+id/textView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/addItemsLaunchTextBox" 
     android:text="Select Place" 
     android:textSize="24sp"/> 

    <EditText 
     android:id="@+id/selectPlaceEditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView7" 
     android:ems="10" 
     android:focusable="false" 
     android:hint="Choose Place" 
     android:inputType="textPersonName" 
     android:onClick="launchChooseLocationActivity"/> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/selectPlaceEditText" 
     android:text="Choose Image" 
     android:textSize="24sp"/> 

    <ImageView 
     android:id="@+id/setImage" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:minHeight="150dp" 
     android:layout_above="@+id/add_reminder" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView3" 
     android:layout_marginStart="24dp" 
     android:layout_marginTop="15dp" 
     android:layout_toStartOf="@+id/addImage" 
     android:layout_marginBottom="10dp" 
     app:srcCompat="@android:drawable/ic_menu_gallery"/> 

    <Button 
     android:id="@+id/add_reminder" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:background="@color/cast_libraries_material_featurehighlight_outer_highlight_default_color" 
     android:elevation="11dp" 
     android:onClick="saveLocationReminder" 
     android:text="Add" 
     android:layout_alignParentBottom="true" 
     android:textColor="@color/cardview_light_background" 
     android:textStyle="normal|bold"/> 


</RelativeLayout> 
0

你的繪製提供所有維度?檢查你的res文件夾,並確保你有drawable-mdpi,drawable-hdpi,drawable-xhdpi等等。

在不同的屏幕尺寸和分辨率下,系統將使用不同的資源,在您的情況下,您只能提供一個圖像。

請參閱本指南developer.android.com