在设备上查看时,为什么图像部分脱离屏幕? [英] Why is image partially out of screen when viewing on device?

查看:71
本文介绍了在设备上查看时,为什么图像部分脱离屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Android工作室添加了一张图片到我的视野中。在Android工作室的xml视图中,图像距底部约1厘米。



当我将程序加载到手机中时,图像的一半位于屏幕之外区域。



我已将视图设备设置为Nexus 5(5英寸),我的手机是Galaxy S4(也是5英寸)。所以那里应该没什么区别。



这是它在编辑器中的样子:

< img src ='http://s15.postimg.org/4gbo4yzkn/alignemtn.jpg'border ='0'alt =alignemtn/>





提前致谢!



Hi,
i added an image in Android studio to my view. The image is about 1cm from the bottom in the xml view in Android studio.

When i load the program into my phone then half of the image is outside of the screen area.

I have set the view device to Nexus 5 (5inch) and my phone is Galaxy S4 (also 5inch). So there should be no difference there.

Here is how it looks in the editor:
<img src='http://s15.postimg.org/4gbo4yzkn/alignemtn.jpg' border='0' alt="alignemtn" />


Thanks in advance!

<?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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.testo.testapp.testapp.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

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







<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="fill_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=".MainActivity$CarrotFragment"

    android:removed="#ffffff">

    <TextView

        android:id="@+id/section_label"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:textAlignment="center"

        android:textSize="@dimen/abc_text_size_large_material"

        />

    <ImageView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:id="@+id/imageView"

        android:src="@drawable/carrot"

        android:layout_gravity="center"

        android:layout_marginBottom="45dp"

        android:layout_alignParentBottom="true"

        android:layout_centerHorizontal="true"/>

    <ImageView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:id="@+id/imageView2"

        android:src="@drawable/carrot"

        android:layout_alignWithParentIfMissing="false"

        android:layout_alignParentBottom="true"

        android:layout_alignParentRight="true"

        android:layout_alignParentEnd="true"/>

</RelativeLayout>





我有什么试过:



我试图修改各种对齐选项,但似乎没什么用。



What I have tried:

I have tried to tinker with all kinds of alignment options but nothing seems to work.

推荐答案

CarrotFragment

< span class =code-attribute> android:removed = #ffffff >

< TextView

android:id = @ + id / section_label

android:layout_width < span class =code-keyword> = match_parent
< span class =code-attribute>
android:layout_height = wrap_content

< span class =code-attribute> android:textAlignment = center

android:textSize = @ dimen / abc_text_size_large_material

/ >

< ImageView

android:layout_width = wrap_content

android :layout_height = wrap_content

android:id = @ + id / imageView

android:src = @ drawable / carrot

android:layout_gravity = center

android:layout_marginBottom = 45dp

android:layout_alignParentBottom = true

android:layout_centerHorizo​​ntal = true / >

< ImageView

< span class =code-attribute>
android:layout_width = wrap_content

android:layout_height = wrap_content

android:id < span class =code-keyword> = @ + id / imageView2

< span class =code-attribute> android:src = @ drawable / carrot

android:layout_alignWithParentIfMissing = false

android:layout_alignParentBottom = true

android:layout_alignParentRight = true

android:layout_alignParentEnd=\"true\"/>

</RelativeLayout>
CarrotFragment" android:removed="#ffffff"> <TextView android:id="@+id/section_label" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:textSize="@dimen/abc_text_size_large_material" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView" android:src="@drawable/carrot" android:layout_gravity="center" android:layout_marginBottom="45dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2" android:src="@drawable/carrot" android:layout_alignWithParentIfMissing="false" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/> </RelativeLayout>





What I have tried:



I have tried to tinker with all kinds of alignment options but nothing seems to work.



What I have tried:

I have tried to tinker with all kinds of alignment options but nothing seems to work.


Your relative layout contains \"fill_parent\" for height. Therefore it is trying span whole screen area. Then you have image view in \"wrap_content\". Therefore it is taking much area so that image could be shown full.

If you really want to fit all view inside display area you need to use weight_sum in parent view and and layout_weight in child view appropriately for manipulating height so that everything dynamically fits into display area, and noting goes out of screen area.
Your relative layout contains "fill_parent" for height. Therefore it is trying span whole screen area. Then you have image view in "wrap_content". Therefore it is taking much area so that image could be shown full.
If you really want to fit all view inside display area you need to use weight_sum in parent view and and layout_weight in child view appropriately for manipulating height so that everything dynamically fits into display area, and noting goes out of screen area.


这篇关于在设备上查看时,为什么图像部分脱离屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆