2017-08-12 26 views
0

我有一個活動的主題爲Theme.AppCompat.Translucent,包含View Pager使用(的圖像示出了在ImageView號)https://github.com/moondroid/CoverFlow完成活動時上的ImageView的或外部的任何查看用戶觸摸

當用戶點擊圖片的外部我想完成我的活動。 我不知道這件事。請幫助解決它!

我的代碼如下

banner.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:coverflow="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#80000000" 
     tools:context=".ActivityCoverflowBanner"> 

     <coverflowLibrary.FeatureCoverFlow 
      android:id="@+id/coverflow" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      coverflow:coverHeight="180dp" 
      coverflow:coverWidth="150dp" 
      coverflow:maxScaleFactor="1.5" 
      coverflow:reflectionGap="-15px" 
      coverflow:rotationThreshold="50" 
      coverflow:scalingThreshold="0.9" 
      coverflow:spacing="0.5" /> 


    </RelativeLayout> 

item.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/frameLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     card_view:cardCornerRadius="10dp" 
     card_view:cardElevation="3dp" 
     card_view:cardPreventCornerOverlap="false" 
     card_view:cardUseCompatPadding="true"> 

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

      <ImageView 
       android:id="@+id/imgBanner" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scaleType="fitXY" 
       android:src="@mipmap/demoimg" /> 

      <ProgressBar 
       android:id="@+id/mProgressBar" 
       style="?android:attr/progressBarStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_marginBottom="@dimen/corner_radius_s" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/txtPackageName" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="@dimen/summary_button_margin" 
        android:gravity="center_horizontal" 
        android:textColor="@color/BlueTextColor" 
        android:textSize="12sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/txtViewMore" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:layout_marginTop="5dp" 
        android:background="@drawable/blackcurvedbutton" 
        android:padding="@dimen/card_margin_top" 
        android:text="@string/view_more" 
        android:textColor="@color/white" 
        android:textSize="10sp" 
        android:textStyle="bold" /> 
      </LinearLayout> 

    </android.support.v7.widget.CardView> 
</FrameLayout> 

的manifest.xml

<activity 
       android:name=".ActivityCoverflowBanner" 
       android:label="@string/title_activity_coverflow_banner" 
       android:screenOrientation="portrait" 
       android:theme="@style/Theme.AppCompat.Translucent" 
       android:windowSoftInputMode="stateHidden|adjustResize" /> 
+0

更新你的答案了View尋呼機XML文件。 –

+0

我已更新我的代碼! –

回答

0

有一個簡單的解決方案來實現你想要的。正好趕上那是不是就ImageView的

設置OnClickListener您的活動點擊的事件,在這之後,覆蓋的方法OnClick讓任何你想要的東西,如果它不是ImageView。下面是一個簡單的例子如何:

public class myActivity implements OnClickListener{ 

    ImageView myImageView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     myImageView = (ImageView)findViewById(R.id.myImageView); 
     myImageView.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     if(v != myImageView) 
      finish(); 
    } 
} 
+0

讓我試試.. !!! –

+0

謝謝,但它不適合我!我有Coverflow ViewPager,我已經設置了上面提到的點擊事件,這是我在適配器中設置的,但它不起作用。 –

+0

但我想你應該首先將監聽器添加到父視圖。其他onClick不會被解僱。 –

1

首先,你需要得到父視圖(例如: - LinearLayout中,相對佈局或東西),它保存ImageView作爲要添加點擊一個孩子或並完成。 如果banner.xml是你的主要xml。然後將監聽器放在RelativeLayoutFeatureCoverFlow(如果它全屏顯示)。

使用setOnClickListener(this)父視圖設置onClickListener

第三 適用@Ricardo回答。

@Override 
public void onClick(View v) { 
    if(v.getId() != R.id.imgBanner) 
     finish(); 
} 

OR

@Override 
public void onClick(View v) { 
    if(v.getId() == R.id.yourParentView) 
     finish(); 
} 
+0

謝謝,但它不工作。 –

相關問題