【发布时间】:2015-04-16 14:16:15
【问题描述】:
我想用代码创建滚动视图,
我已经创建了滚动视图和线性布局,但没有滚动到底部,
我应该怎么做才能滚动
你可以在下面的链接http://screencast.com/t/bbDcDWoScPyM找到截图
这里是活动 xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rlt"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
tools:context="com.test.test.test">
</RelativeLayout>
这里是java代码
RelativeLayout lL = (RelativeLayout) findViewById(R.id.rlt);
ScrollView sv= new ScrollView(this);//(ScrollView) findViewById(R.id.svScroll);
LinearLayout sahne = new LinearLayout(this);
sahne.setOrientation(LinearLayout.VERTICAL);
txt1.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
txt2.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
txt3.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
txt4.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
txt5.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
txt6.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
txt7.setLayoutParams(new LinearLayout.LayoutParams(textRequireWidth,textRequireHeight));
sahne.addView(txt1);
sahne.addView(txt2);
sahne.addView(txt3);
sahne.addView(txt4);
sahne.addView(txt5);
sahne.addView(txt6);
sahne.addView(txt7);
sahne.addView(btn1);
sv.addView(sahne);
lL.addView(sv);
【问题讨论】:
-
您是否尝试在
ScrollView和LinearLayout上设置布局参数? -
你试过为 ScrollView sv 和 LinearLayout sahne 设置 layout_width 和 layout_height 吗?我相信这些参数是必需的。
-
可以,但不起作用
标签: android android-studio android-scrollview