【发布时间】:2018-05-06 03:23:44
【问题描述】:
我正在处理一个问题,希望你能帮助我。
我想禁用滚动视图中的所有子项,但我希望能够滚动并保持视图的外观与启用时相同。
我的布局:
<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);
}
}
}
在滚动视图中创建另一个视图并在需要时设置可见,滚动不起作用。
关于如何做到这一点的任何建议?
提前致谢。
【问题讨论】:
标签: android