android - 如何在动态添加内容时使线性布局自动滚动

标签 android android-linearlayout horizontal-scrolling

我的应用程序包含不同的布局。其中一个是线性布局。它的内容是动态添加的。我想让这个布局在添加内容时水平滚动。为此,我编写了下面给出的代码..

 <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);

        }

在这种方法中,它向我的布局添加了更多内容...

最佳答案

<ScrollView>作为父布局...

关于android - 如何在动态添加内容时使线性布局自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6353737/

相关文章:

java - 比较谷歌地图 v2 android 中的两个 LatLng 对象

android - 如何从服务中获取值(value)到android中的 Activity ?

android - 强制 aapt 在构建期间重新评估原始资源

java - 为什么我的 EditText 被布局覆盖?

Android:禁用滚动边缘的 Horizo​​ntalScrollView 结束

css - 水平滚动条仅在 IE7 中出现,即使溢出 :hidden being set

android - 无法在调试器中逐步执行代码 (Android)

android - 将复选框对齐到LinearLayout android中的右侧

android - 图像拉伸(stretch)

javascript - 整页水平滑动,有规律的垂直滚动