2014-03-31 54 views
0

我使用视图顶部的图像视图创建视图。 图像大小为1080-800px。如果我看看我的HTC One,它是完美的。图像宽度占全屏。如果我采取另一种更大或更小的设备,图像会变小或变大!我把图像放到drawable-xxhdpi文件夹中。 我应该用photoshop将它们缩放到不同的尺寸吗?将图像视图缩放到不同的设备

enter image description here

可以看到,大小在左边是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> 

回答

2

更改此

android:layout_width="wrap_content" 

这个

android:layout_width="match_parent" 

,并添加

android:adjustViewBounds="true" 
+0

我觉得这个答案加上@ Wael的答案是最好的选择 - Wael的答案很好,因为你不会将非常大的图像拖入内存中,只能使用缩放版本(这可能导致OOM错误),而TheOsirian的答案涵盖了确保图像的所有基础显示到屏幕的全部宽度,而不是平铺 – panini

+0

我已经将此添加到我的两个图像视图中,但没有任何更改。 – basti12354

+0

也许你需要设置'android:scaleType =“centerInside”'。 – TheOsirian

2

把你的形象(名称相同),不同分辨率的

drawable-hdpi, drawable-mdpi, drawable-ldpi, drawable-xhdpi, drawable-xxhdpi 

enter image description here

使Android将自动选择与您的屏幕分辨率图像

+0

谢谢,我把我的1080 * 800大小的图像放到xxhdpi上?我应该把更大的那个放在哪里? – basti12354

+0

你应该放大drawable-xhdpi和最大drawable-xxhdpi,你应该尝试和测试 – wael