安卓:ImageView的规模再上滚动型内屏幕宽度 [英] Android: ImageView scale to screen width within a ScrollView

查看:226
本文介绍了安卓:ImageView的规模再上滚动型内屏幕宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的到Android编程,我和我的布局偶然发现了一个问题

起初,我有一个的LinearLayout 的TextView 2 按钮的ImageView 缩放以适合屏幕。

现在我想把这个下滚动视图,所以的ImageView 可缩放的放大(到屏幕的宽度)。

如果没有滚动视图一切就​​都很好,但与滚动视图,我的的ImageView 不再被缩放。

我在做什么的错误?我试了多种解决方案的计算器,但我不能让它与滚动型工作。在此先感谢!

 <?XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>
<的LinearLayout
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    >    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =CENTER_HORIZONTAL
        机器人:文字=@字符串/帮您做生意/>    <按钮
        机器人:ID =@ + ID /按钮1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =CENTER_HORIZONTAL
        机器人:文字=@字符串/ TEXTA/>    <按钮
        机器人:ID =@ + ID /按钮2
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =CENTER_HORIZONTAL
        机器人:文字=@字符串/ TEXTB/>    < ImageView的
        机器人:ID =@ + ID / imageView1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =CENTER_HORIZONTAL
        机器人:adjustViewBounds =真
        机器人:scaleType =fitCenter
        机器人:SRC =@绘制/第1页/>< / LinearLayout中>
< /滚动型>


解决方案

请的LinearLayout / RelativeLayout的父视图。在使滚动视图,并设置alignparentTop =真。这种滚动视图将包含一个单一的布局中,所有其他的意见将被放置。

I'm quite new to android programming and I stumbled upon a problem with my layout.

At first, I had a Linearlayout with a textview, 2 buttons and a imageview scaled to fit the screen.

Now I wanted to put this under a scrollview, so the imageview could be scaled larger (to the width of the screen).

Without the scrollview everything just went fine, but with the scrollview, my imageview is not scaled anymore.

What am I doing wrong? I tried numerous solutions on StackOverflow but I can't get it to work with a ScrollView. Thanks in advance!

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/pageno" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/texta" />

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/textb" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/page1" />

</LinearLayout>
</ScrollView>

解决方案

Make LinearLayout/RelativeLayout as parent view. In that make a scroll view and set alignparentTop=true. This scrollView will contain a single layout in which all other views will be placed.

这篇关于安卓:ImageView的规模再上滚动型内屏幕宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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