0

我有一个 XML 膨胀的自定义视图类。它包括按钮和网页视图。我将此视图类添加到 mainactivity(VividViewerActivity)。我第一次将可见性设置为不可见。在这个主要活动中有一个方法(loadPrintActivity),我将视图类的可见性设置为可见。一切正常。但是触摸对我不起作用。这是我的课:

public class PrintView extends RelativeLayout {
Button btnClose,btnPrint;
WebView wev;
public PrintView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    View.inflate(context, R.layout.printscreen, this);
    wev = (WebView) findViewById(R.id.webViewPrint);
    btnClose = (Button)findViewById(R.id.btnClose);
    btnPrint = (Button)findViewById(R.id.btnPrint);
    btnClose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d("VIEWWWWWWWWWWWWWWWWWWWWW", "kaj korce..............");
            btnPrint.setVisibility(View.INVISIBLE);
        }
    });
}


@Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    return super.onTouchEvent(event);
}


@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // TODO Auto-generated method stub
    for(int i = 0 ; i < getChildCount() ; i++){
        getChildAt(i).layout(l, t, r, b);
       }
}

这是我的 XML 布局:

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

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/top"
        android:gravity="center" >

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

            <Button
                android:id="@+id/btnClose"
                android:layout_width="80dp"
                android:layout_height="30dp"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="10dp"
                android:background="@drawable/btn"
                android:text="Close" />

            <Button
                android:id="@+id/btnPrint"
                android:layout_width="80dp"
                android:layout_height="30dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                android:background="@drawable/btn"
                android:text="Print" />

        </RelativeLayout>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <TableRow
                android:id="@+id/tableRow7"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <WebView
                    android:id="@+id/webViewPrint"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1" />

            </TableRow>
        </TableLayout>

    </TableRow>
</TableLayout>

这是我的活动:

 public class VividViewerActivity extends Activity{

private UnityPlayer mUnityPlayer;

private JSInterface mJSInterface;   // JavaScript interface (message receiver)

 private WebView mWebView;           // WebView object
    private ProgressBar mProgress;      // Progress bar
    private int mLeftMargin;            // Margins around the WebView
    private int mTopMargin;
    private int mRightMargin;
    private int mBottomMargin;
    private boolean mInitialLoad; 
    Context context;

    PrintView pv;

protected void onCreate (Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    mUnityPlayer = new UnityPlayer(this);

    context = this;

    if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
        getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
                               WindowManager.LayoutParams.FLAG_FULLSCREEN);

    int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
    boolean trueColor8888 = false;
    mUnityPlayer.init(glesMode, trueColor8888);

    View playerView = mUnityPlayer.getView();
    setContentView(playerView);
    playerView.requestFocus();

    mJSInterface = new JSInterface();        

    Log.e("Cookie", "COOKIE SUPPORT!");

        mWebView = new WebView(this);

        FrameLayout layout = new FrameLayout(this);
        addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        layout.addView(mWebView, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY));
        // Basic settings of WebView.

        mWebView.setBackgroundColor(Color.TRANSPARENT);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setSupportZoom(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setPluginsEnabled(true);



        mWebView.setWebViewClient(new WebViewClient(){});

        pv = new PrintView(context);
        layout.addView(pv, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY));
        mWebView.addJavascriptInterface(mJSInterface, "UnityInterface");

        // Start in invisible state.
        mWebView.setVisibility(View.GONE);

        pv.setVisibility(View.INVISIBLE);

}

这是方法:

 public void loadPrintActivity(String printUrl){
   Constant.printUrl = printUrl;
   Constant.isPrintButtonVisible = true;
   WebSettings webSettings = pv.wev.getSettings();
   webSettings.setSupportZoom(true);
   webSettings.setJavaScriptEnabled(true);
   webSettings.setPluginsEnabled(true);
   pv.wev.setWebViewClient(new WebViewClient(){});
   pv.wev.loadUrl(printUrl);
   pv.setVisibility(View.VISIBLE); }
4

2 回答 2

0

您必须将此属性设置为视图和视图。

在 parenview 布局文件中

android:clickable="true"

在 Childview 布局文件中

android:clickable="false"

这将是工作。

于 2013-10-09T09:14:52.520 回答
0

像这样更改您的视图代码,

 View v=View.inflate(context, R.layout.printscreen, this);
    wev = (WebView) v.findViewById(R.id.webViewPrint);
    btnClose = (Button)v.findViewById(R.id.btnClose);
    btnPrint = (Button)v.findViewById(R.id.btnPrint);
于 2013-10-09T05:46:36.460 回答