如何使线性布局在动态添加其内容时自动滚动
我的应用程序包含不同的布局。其中一个是线性布局。它的内容是动态添加的。我想让这个布局在添加其内容时水平滚动。为此我编写了下面给出的代码..
<LinearLayout android:id="@+id/scoreballparent_layout"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_above="@+id/score_layout">
<HorizontalScrollView android:layout_height="wrap_content"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/scoreball_layout"
android:layout_height="wrap_content"
>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
它正在工作..但是我想要在添加内容时自动滚动它...任何人都可以帮助我...
更多源代码:
private void scoreball_display(String score)
{
addscoreball = new Button(getApplicationContext());
addscoreball.setId(134);
if(score=="WD" || score=="NB")
{
addscoreball.setTextAppearance(this,R.style.plainText);
}
else{
addscoreball.setTextAppearance(this,R.style.BoldText);
}
addscoreball.setText(score);
addscoreball.setSingleLine(true);
addscoreball.setBackgroundDrawable(getResources().getDrawable (R.drawable.white_ball));
addscoreball.setGravity(Gravity.CENTER_HORIZONTAL);
addscoreball.setGravity(Gravity.CENTER_VERTICAL);
LinearLayout.LayoutParams addscoreball_Params =
new LinearLayout.LayoutParams(35,35);
scoreballlayout.addView(addscoreball,addscoreball_Params);
}
在这种方法中,它正在向我的布局添加更多内容...
My application containing different layouts.one of them is a linear layout.it's content is dynamically adding.i want to make this layout horizontally scrollable while adding its content.for that i wrote the code given below..
<LinearLayout android:id="@+id/scoreballparent_layout"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_above="@+id/score_layout">
<HorizontalScrollView android:layout_height="wrap_content"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/scoreball_layout"
android:layout_height="wrap_content"
>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
it is working..but i want to scroll it automatically while adding contents...can anybody help me plz...
more source code:
private void scoreball_display(String score)
{
addscoreball = new Button(getApplicationContext());
addscoreball.setId(134);
if(score=="WD" || score=="NB")
{
addscoreball.setTextAppearance(this,R.style.plainText);
}
else{
addscoreball.setTextAppearance(this,R.style.BoldText);
}
addscoreball.setText(score);
addscoreball.setSingleLine(true);
addscoreball.setBackgroundDrawable(getResources().getDrawable (R.drawable.white_ball));
addscoreball.setGravity(Gravity.CENTER_HORIZONTAL);
addscoreball.setGravity(Gravity.CENTER_VERTICAL);
LinearLayout.LayoutParams addscoreball_Params =
new LinearLayout.LayoutParams(35,35);
scoreballlayout.addView(addscoreball,addscoreball_Params);
}
in this method it is adding more contents to my layout...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
作为父布局...Put
<ScrollView>
as parent layout...添加新元素时,您必须更新 UI,
首先使用以下代码初始化 HorizonatlScrollView
添加新元素时,使用以下行滚动您的 HorizontalScrollView
谢谢
迪帕克
You have to update your UI when new element is added
first initialize HorizonatlScrollView using the following code
when a new element is added use the following line there to scroll your HorizontalScrollView
Thanks
Deepak
有一个 scrollTo 方法,请参阅 http ://developer.android.com/reference/android/widget/HorizontalScrollView.html#scrollTo(int, int)
There is a scrollTo method, see http://developer.android.com/reference/android/widget/HorizontalScrollView.html#scrollTo(int, int)