我正在处理一个问题,希望你能帮助我。
我想禁用scrollview中的所有子项,但我希望能够滚动并保持视图的外观与启用它们时的相同。
我的布局:
<ScrollView
android:id="@+id/newEventScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/eventLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<com.xw.repo.BubbleSeekBar
android:id="@+id/durationBubble"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:bsb_bubble_color="@color/colorPrimaryDarker"
app:bsb_bubble_text_color="@color/colorWhite"
app:bsb_max="12"
app:bsb_min="0"
app:bsb_progress="0"
app:bsb_second_track_color="@color/colorPrimaryDarker"
app:bsb_section_count="2"
app:bsb_section_text_position="below_section_mark"
app:bsb_show_progress_in_float="true"
app:bsb_show_section_mark="true"
app:bsb_show_section_text="true"
app:bsb_show_thumb_text="false"
app:bsb_thumb_radius="8dp"
app:bsb_track_color="@color/colorWhite" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/hearingLoss" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/hearingLossSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColorHint="@color/colorPrimaryDark"
android:theme="@style/SCBSwitch" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
我需要的是不要让用户更改任何视图,例如switch或seekBar。 我试过这件事:
禁用嵌套视图,滚动工作但禁用我不喜欢的外观。
private void disableEnableControls(boolean enable, ViewGroup vg){
for (int i = 0; i < vg.getChildCount(); i++){
View child = vg.getChildAt(i);
child.setEnabled(enable);
if (child instanceof ViewGroup){
disableEnableControls(enable, (ViewGroup)child);
}
}
}
在OnClickListener上不执行任何操作,滚动无法正常工作
private void disableEnableControls(boolean enable, ViewGroup vg){
for (int i = 0; i < vg.getChildCount(); i++){
View child = vg.getChildAt(i);
child.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
if (child instanceof ViewGroup){
disableEnableControls(enable, (ViewGroup)child);
}
}
}
在scrollview中创建另一个视图,并在需要时设置可见,滚动不工作。
有关如何执行此操作的任何建议吗?
提前致谢。
答案 0 :(得分:0)
如果你想要禁用一个视图(我假设你正在讨论那些带有点击监听器或复选框的视图......),你可以简单地禁用点击监听器(如果这是你想要的)您的java代码:在侦听器回调方法中设置if条件,或者将视图的可单击功能设置为false。