Horizo​​ntalScrollView 中的 Android ImageView 获取屏幕宽度的两倍

标签 android android-layout

我试图在 Horizo​​ntalScrollView 中制作一个 ImageView,但是 imageView 的宽度是屏幕的两倍,并且在中途结束时超出了边界。

我的 XML:

<?xml version="1.0" encoding="utf-8"?>

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:baselineAligned="true"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/penguins" />
</LinearLayout>

</HorizontalScrollView>

And a image of what I get (click me!)

有谁知道这个问题的解决方案吗?

问候

最佳答案

我复制了你的 xml 并使用我的资源,它看起来很完美,我相信你的资源比你想象的要大,你可能应该使用 layout_widthlayout_height 作为修复大小并将 scaleType 设置为 centerInside。

关于Horizo​​ntalScrollView 中的 Android ImageView 获取屏幕宽度的两倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10609289/

相关文章:

java - 出现错误 java.lang.RuntimeException : Unable to start activity ComponentInfo

android - 为什么 ProgressBar 没有消失?

android - 将 fragment 添加到 fragment

android - 支持屏幕尺寸 - DP 不工作

android - 自定义 Android View 在线性和相对布局中显示不同

java - 如何在BroadcastReceiver和main方法之间传递信息

android - 仅在牛轧糖上出现 TransactionTooLargeException

android - 在 TabLayout 支持库中以编程方式设置选项卡指示器位置

java - 如何添加列表 Activity 而不是 fragment ?

安卓工作室 : Cannot resolve symbol AsyncTask