【发布时间】:2022-03-17 16:03:30
【问题描述】:
<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>
这是我的 xml 文件。可惜很简单。我的意图是动态增加滚动视图的高度,并且图像(与滚动视图一起)视图将逐渐显示。所以我该怎么做以及这里的 rootLayout 是什么以及如何从我的代码中调用 rootLayout ??
final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
runOnUiThread(new Runnable()
{
public void run() {
secondCounter++;
yourNewHeight += 10;
sv.getLayoutParams().height = yourNewHeight;
LinearLayout root = (LinearLayout) findViewById(R.id.rootLayout);
root.invalidate();
Log.v("", "" +sv.getLayoutParams().height);
if(secondCounter == 20){
timer.cancel();
}
}
});
}
}, delay, period);
这是我在 java 文件中的代码。但它不起作用。伙计们你能帮帮我吗..!!!
【问题讨论】:
-
请注意,
AbsoluteLayout已长期贬值,您应该使用替代方案。 -
使用相对布局而不是你不必增加 gridview 给它包装内容,你必须在线性布局中动态添加图像,这将在滚动视图下
-
谢谢.. :-) 但是当我使用线性布局时,我无法在 XMl 中正确放置项目。
标签: android