【发布时间】:2014-11-06 09:01:54
【问题描述】:
任何想法为什么我的 ImageButton 不能在我的 Fragment 中工作? ImageButton 包含一个 Drawable 并且是透明的。 当我将它放在下面的 RelativeLayout 中时,它的工作...
<RelativeLayout
android:id="@+id/rl_newsdet_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/bg"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_newsdet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginTop="7dp"
android:textSize="20sp"
android:layout_centerHorizontal="true"
/>
<ImageButton
android:id="@+id/btn_newsdet_back"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/bt_back"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
android:background="@color/white"
android:gravity="left"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_newsdet_name"
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:textColor="@color/cyan"
android:background="@color/grey"
android:paddingLeft="1dp"
android:paddingRight="1dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_newsdet_time"
android:textColor="@color/white"
android:textSize="18sp"
android:layout_toRightOf="@+id/tv_newsdet_name"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:background="@color/grey"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/tv_newsdet_text"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:layout_below="@+id/tv_newsdet_name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
我的带有 AndroidAnnotations 的 onClickListener
@ViewById
ImageButton btn_newsdet_back;
@Click(R.id.btn_newsdet_back)
void back() {
Log.i(TAG,"back");
mActivity.popFragments();
}
编辑 当 onClick 在 TextView 下方时,它正在工作(调用)。谁能解释一下为什么?
【问题讨论】:
-
“不工作”是什么意思?
-
正如我在标题中所写,onClick 不起作用。对我来说,按钮似乎无法访问,但我不知道为什么。
-
再次“不工作”并不是很清楚。日志是写的,还是不写的?只是没有执行的“popFragments()”吗?我们无法知道您期望的行为以及实际发生的情况。
-
onClick 不起作用:未调用 onClick。透明的 ActionBar 可能是一个可能的原因吗?
-
我问了两个问题,你一个都没回答。
标签: android android-imagebutton