这是我的布局的样子:
我有一个父活动,它有一个自定义视图(view1自己处理onTouch事件)和2个按钮(view2和view3). DialogFragment显示了可见的布局,其余部分是透明的.
我的对话框片段如下所示:
public class FragmentText extends DialogFragment{
public static FragmentText newInstance() {
FragmentText frag = new FragmentText();
frag.setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Translucent_NoTitleBar);
return frag;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
// instantiate the custom layout
final View layout = inflater.inflate(R.layout.fragment_layout, null);
.....
}
}
并且布局文件如下所示:
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="70dp"
android:background="@color/transparent"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="70dp" >
android:id="@+id/layContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:background="@drawable/bk_text_edit"
android:orientation="vertical"
android:padding="@dimen/margin" >
all my layouts and buttons
和
public class TransparentView extends LinearLayout {
@SuppressLint("NewApi")
public TransparentView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public TransparentView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TransparentView(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return false; // event get propagated
}
}
当用户按下DialogFragment的可见布局时,我希望:
1.关闭对话框片段
2.将onTouch传递给父活动,并允许用户与视图交互.
所以基本上如果我将手指拖到View1上,我想要关闭对话框并继续我对view1的拖动交互.
这有可能实现吗?
LE:这也行不通:
layMain.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
getActivity().dispatchTouchEvent(event);
return false;
}
});