如何以编程方式删除scrollview(e.q。禁用/启用wordwrap)?

时间:2014-12-04 20:59:35

标签: android scrollview horizontalscrollview

XML(变体1) - 文本WORD WRAP OFF:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<HorizontalScrollView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">

    <EditText
        android:inputType="textMultiLine|textNoSuggestions"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

</HorizontalScrollView>

</LinearLayout>

如何删除Horizo​​ntalScrollView programmaticaly,之后应该是XML,如: XML(变体2) - TEXT WORD WRAP ON

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<EditText
android:inputType="textMultiLine|textNoSuggestions"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>

    </LinearLayout>

这样做的恰当方法是: 也许使用动态片段?也许使用View.removeView? 要么.... 请帮忙......

1 个答案:

答案 0 :(得分:0)

此代码应删除滚动视图并将项目放在其中(为此,请确保将ID添加到xml上的视图元素)。

View bodyLayout = (View)m_dialog.findViewById(R.id.my_item);
ScrollView scroller = (ScrollView)m_dialog.findViewById(R.id.my_scroll);
ViewGroup topLayout =  (ViewGroup)scroller.getParent();
ViewGroup.LayoutParams params = scroller.getLayoutParams();
int index = topLayout.indexOfChild(scroller);
scroller.removeAllViews();
topLayout.removeView(scroller);
topLayout.addView(bodyLayout, index, params);