您的位置:首页 > 其它

HorizontalScrollView 动态添加View后 滚动到最后一个 最右边

2014-05-23 12:12 281 查看
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    mBtnD.setVisibility(View.VISIBLE);
                    Timer timer=new Timer();
                    timer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            mHsv.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                        }
                    },100L);
                }else {
                    mBtnD.setVisibility(View.GONE);
                }
            }
        });


<pre name="code" class="html"><pre name="code" class="html">    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <HorizontalScrollView
            android:id="@+id/hsv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:scrollbars="none">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/btnA"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="A"/>

                <Button
                    android:id="@+id/btnB"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="B" />

                <Button
                    android:id="@+id/btnC"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="C" />

                <Button
                    android:id="@+id/btnD"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="gone"
                    android:text="D" />

                <CheckBox
                    android:id="@+id/checkBox"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:button="@drawable/checkBox_style" />
            </LinearLayout>
        </HorizontalScrollView>
    </RelativeLayout>





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐