完成活动时上的ImageView的或外部的任何查看用户触摸
我有一个活动的主题为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" />
有一个简单的解决方案来实现你想要的。正好赶上那是不是就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();
}
}
让我试试.. !!! –
谢谢,但它不适合我!我有Coverflow ViewPager,我已经设置了上面提到的点击事件,这是我在适配器中设置的,但它不起作用。 –
但我想你应该首先将监听器添加到父视图。其他onClick不会被解雇。 –
首先,你需要得到父视图(例如: - LinearLayout中,相对布局或东西),它保存ImageView
作为要添加点击一个孩子或并完成。 如果banner.xml
是你的主要xml。然后将监听器放在RelativeLayout
或FeatureCoverFlow
(如果它全屏显示)。
二 使用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();
}
谢谢,但它不工作。 –
更新你的答案了View寻呼机XML文件。 –
我已更新我的代码! –