我正在处理一个问题,希望你能帮我。
我想禁用滚动视图中的所有儿童,但我希望能够滚动并保持视图的外观,就像它们处于启用状态一样。
我的布局:
<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);
}
}
}在滚动视图中创建另一个视图,并设置当我想要时可见,滚动不起作用。
对如何做到这一点有什么建议吗?
提前谢谢。
发布于 2018-05-05 03:31:29
如果你想禁用一个视图(我假设你说的是带有click listeners或checkboxes的视图,...),你可以在java代码中简单地禁用click listeners (如果这是你想要的):或者在listener回调方法中设置一个if条件,或者将视图的clickable特性设置为false。
https://stackoverflow.com/questions/50180931
复制相似问题