防止ImageView将屏幕推到屏幕外

问题描述:

我有一个线性布局,其中包含一个imageview和另一个线性布局,它是屏幕上的底部条。我在我的项目的其他地方使用底部栏,我不认为这是问题。防止ImageView将屏幕推到屏幕外

问题是imageview占据了整个屏幕。图像本身不,但是视图确实如此。我似乎无法弄清楚这一点。正如你可以看到我的XML,我没有使用fill_parent的图像视图,我已经尝试了图像的每个可能的scaleType。

有什么建议吗?此外,如果它有助于我构建Android API 8

编辑:我已经改变了下面的XML,以便您可以使用我写的。 (这是我在图像视图中使用的图像:http://i.imgur.com/qN5aT.jpg

<?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:background="#FFFFFF" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitStart" 
     android:src="@drawable/quote_sample_img" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="This is text" /> 
    </LinearLayout> 

</LinearLayout> 

http://i.imgur.com/m3msH.png (对不起没有足够的声誉后的实际图片)

+0

您是否尝试过使用layout_weight属性来设置imageview布局和第二个linearlayout之间的空间量之间的固定比例?它怎么样? – pogo2065 2012-03-13 02:43:49

+0

,这样的工作,但不是我期望的方式。我只是玩了一大堆参数,当我给图像一个layout_weight =“。8”和一个线性布局以及一个“.2”布局权重时,底部的条出现了。奇怪的是我给线性布局的权重越多,出现的越少。这对我来说毫无意义。任何想法为什么会发生? – amc6 2012-03-13 03:08:16

+0

即使它看起来工作,我仍然担心前进,因为我不得不添加更多的视图,我不知道它是否会继续工作,或者它是否会在多个屏幕上工作 – amc6 2012-03-13 03:13:32

的东西,看起来,如果机器人的工作:layout_weight =“1.0”被添加到ImageView的。

(我不确定究竟是什么发生,在布局算法什么顺序所以不能解释为什么。)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#FFFFFF" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1.0" 
     android:scaleType="fitStart" 
     android:src="@drawable/quote_sample_img" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="This is text" /> 
    </LinearLayout> 

</LinearLayout> 
+1

是的,它修复了它,但它对我仍然没有任何意义。 layout_weight不应该使imageview尽可能大,而不是更小? – amc6 2012-03-15 02:40:39

+1

将layout_weight设置为1.0并不总是与说视图尽可能大一样。这取决于我们分配给设计中其他视图的重量。看看这篇文章的更多细节http://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean – HenrikS 2012-03-15 04:23:10

+0

这是我的生活一个小时,因为这没有道理! – 2016-10-17 10:51:36

我认为这个问题可能是你使用的图像比屏幕大,所以ImageView的高度设置为可用空间的高度,以便最适合图像,而不会留下任何空间。

此外,如果你想永远有底部栏可见,最好使用RelativeLayout的,而不是像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/Main" 
    android:orientation="vertical" > 
    <LinearLayout 
     android:id="@+id/bottom_bar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" > 
     <include layout="@layout/browse_bottom_bar" /> 
    </LinearLayout> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/bottom_bar" 
     android:src="@drawable/quote_sample_img" /> 
</RelativeLayout> 
+0

我早先使用relativelayout,但我最初认为我不正确地使用它并导致我发布的问题。我切换到LinearLayout,问题依然存在,所以我发布了这个问题。我会稍后再切换。你是对的,源图像最初比屏幕大,直到它被调整大小。但是在调整大小之后,imageview仍然会占用整个屏幕http://i.imgur.com/m3msH.png – amc6 2012-03-13 04:09:32

我有一个非常类似的问题,贴在https://stackoverflow.com/questions/9765401/imageview-with-adjustviewbounds-seems-to-ignore-following-elements

它看起来缩放图像后ImageView不会缩小,除非指定adjustviewbounds =“true”。

但是,正如你可以从我自己的帖子中看到的那样,并不是完整的答案:imageview可能仍然会将下面的项目从显示器中推出,或者如果图像太大,就会侵入它们的空间,我正在努力尝试修理。

+0

Kai的帖子下面包含了什么似乎是缺少的链接...首先声明固定页脚,然后是以imageview结尾的顶部。 如果您的布局更复杂,天堂会帮助您... – Ian 2012-03-19 07:01:11

这是图像中的wrap_content - 源文件可能太高。

使用此在您的ImageView造成的图像区域重置为图像的新大小缩放后:

android:adjustViewBounds="true" 

我也想改变的ImageView的高度,使其充满屏幕,迫使你的吧总是在底部:

android:layout_height="0dip" // faster than match_parent for weight 
android:layout_weight="1.0"