RelativeLayout内容超出了屏幕大小

时间:2017-08-01 20:56:19

标签: android android-relativelayout

在代码中我只给出了dp中图像的高度和宽度。但屏幕的整个内容仍然以较低的屏幕尺寸离开屏幕。我已经在模拟器和真实设备上进行了测试,它在5.5英寸屏幕上看起来不错,而且在其他屏幕尺寸上看起来不太好。

请在下面找到代码。 邮件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

3 个答案:

答案 0 :(得分:0)

检查这个库我正在使用它并解决了我的问题,希望能解决你的问题 https://github.com/intuit/sdp

答案 1 :(得分: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>

答案 2 :(得分:0)

您是否为所有尺寸提供drawable?检查您的id | member | conversation | message | timestamp 文件夹,确保您有drawable-mdpi,drawable-hdpi,drawable-xhdpi等。

在不同的屏幕尺寸和分辨率下,系统将使用不同的资源,在您的情况下,您只需提供一张图像。

请参阅本指南developer.android.com

相关问题