我使用视图顶部的图像视图创建视图。 图像大小为1080-800px。如果我看看我的HTC One,它是完美的。图像宽度占全屏。如果我采取另一种更大或更小的设备,图像会变小或变大!我把图像放到drawable-xxhdpi文件夹中。 我应该用photoshop将它们缩放到不同的尺寸吗?将图像视图缩放到不同的设备
可以看到,大小在左边是PERFEKT,但我怎么能处理这样一个在右边更大的设备?
代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/layout">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crunch"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crunch1" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crunch2" />
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/crunch" />
<TextView
android:id="@+id/TVTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="@+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="verlaufKlick"
android:text="@string/pause"
android:visibility="invisible"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
我觉得这个答案加上@ Wael的答案是最好的选择 - Wael的答案很好,因为你不会将非常大的图像拖入内存中,只能使用缩放版本(这可能导致OOM错误),而TheOsirian的答案涵盖了确保图像的所有基础显示到屏幕的全部宽度,而不是平铺 – panini
我已经将此添加到我的两个图像视图中,但没有任何更改。 – basti12354
也许你需要设置'android:scaleType =“centerInside”'。 – TheOsirian