【问题标题】:How to show an Image gradually within the ScrollView?如何在 ScrollView 中逐渐显示图像?
【发布时间】:2012-07-13 06:43:26
【问题描述】:

是否有任何过程在运行时逐渐增加 ScrollView 的高度。我的意图是逐渐显示 ScrollView 内的图像。所以我想增加 ScrollView 的高度。有什么办法可以完成我的工作吗??请帮帮我。我的 XmlFile 的内容是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rootLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:scrollbars="none"
        android:layout_x="0dp"
        android:layout_y="0dp"
        android:fillViewport="true" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="0dp"
        android:src="@drawable/background" />
        </LinearLayout>

    </ScrollView>

    </LinearLayout>

我的代码是:

final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
          runOnUiThread(new Runnable()
            {
                public void run() {

                    secondCounter++;
                    yourNewHeight += 10;
                    // sv is object of scroll view
                    sv.getLayoutParams().height = yourNewHeight;

                    root.invalidate(); // root is rootview


                    if(secondCounter == 20){
                        timer.cancel();
                    }
                }
            });
        }
    }, delay, period);

这是我的屏幕截图:

模糊图像在 Scrollview 中,随着 ScrollView 高度的增加,模糊图像逐渐显示。

【问题讨论】:

  • 您是否以编程方式在图像上添加更多内容??
  • 没有。滚动视图中只有一张图片。
  • 请告诉我你想展示什么。如果只有一张图片而不是你为什么要在滚动视图中添加??
  • 在代码中使用setLayoutParams(..) 以编程方式设置宽度和高度。
  • 嗯....!!!只有一个图像。我的意图是逐渐增加scrollView的高度,以便可以显示其中的图像..等待我在这里发布一些屏幕截图..!!!

标签: android xml android-imageview android-scrollview


【解决方案1】:

我已经编辑了你的代码..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="80dp">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width=" fill_parent"
        android:layout_height="wrap_content" >


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

</ScrollView>

让我知道是否已完成此操作.. 好的..

【讨论】:

    【解决方案2】:

    您可以使用setLayoutParams(..) 以编程方式设置宽度和高度。查看 mao 给here 的问题和解决方案。

    【讨论】:

    • 滚动视图的高度不会固定,会定期增加。
    猜你喜欢
    • 2011-08-26
    • 1970-01-01
    • 2011-03-25
    • 2019-08-21
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多