簡體   English   中英

RelativeLayout的內容超出了屏幕尺寸

[英]RelativeLayout contents are going beyond the screen size

在代碼中,我只給了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寸屏

4.7英寸屏幕 4.7英寸屏幕

5.5寸屏幕 5.5寸屏幕

檢查這個庫我正在使用它並解決了我的問題,希望解決您的https://github.com/intuit/sdp

試試這種布局,

<?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>

您是否提供所有尺寸的可繪制對象? 檢查res文件夾,並確保您具有drawable-mdpi,drawable-hdpi,drawable-xhdpi等。

在不同的屏幕尺寸和分辨率下,系統將使用不同的資源,並且在您遇到的情況下,您似乎僅提供一張圖像。

請參考本指南developer.android.com

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM