我已閱讀其他帖子。我仍然無法找到解決方案。爲什麼先點擊ImageView不起作用?
我試圖把
android:focusableInTouchMode="false"
android:focusable="false"
沒有奏效。 我已包括
android:clickable="true"
沒有工作。
在Java代碼中,我已經包括
imgLeft.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
v.performClick();
}
}
});
與onClickListener
一邊()。
但仍然沒有奏效。
這是我粗略的佈局結構和圖像視圖的位置。
<RelativeLayout>
<FrameLayout>
<LinearLayout>
<Relativelayout>
<LineatLayout/>
<LinearLayout>
<LinearLayout>
<ImageView <--- This is the I needed to click.
android:id="@+id/imgLeft"
android:layout_width="wrap_content"
android:layout_height="@dimen/title_img_width"
android:src="@drawable/left"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</Relativelayout>
</LinearLayout>
</FrameLayout>
</Relativelayout>
我正在使用setOnClickListener來處理單擊事件。
imgLeft.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//some function here <-- **This function triggers only after the second click**
}
});
注: 我徹底檢查其它計算器職位。但它們都沒有解決的問題..是有上述
更新任何解決方案:原始代碼:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_image" >
<FrameLayout
android:id="@+id/layoutConfiguration"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/bg_image"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/menu_header_height" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1" >
<LinearLayout
android:id="@+id/ll_menu"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="@dimen/menu_top_icon"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="5dp"
android:src="@drawable/menu" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.68"
android:fontFamily="Oswald-Regular.ttf"
android:gravity="center"
android:text="Connect Bluetooths"
android:textColor="#fff"
android:textSize="@dimen/menu_tital_textsize" />
<!-- android:padding="@dimen/menu_tital_padding" -->
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:gravity="center"
android:padding="15dp"
android:text=""
android:textColor="#fff"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/ll_sole"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/tital_margin_top"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_leftBattery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="100%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/holo_red_dark"
android:textSize="16sp"
android:visibility="gone" />
<ImageView
android:id="@+id/imgLeftBluetooth"
android:layout_width="wrap_content"
android:layout_height="@dimen/title_img_width"
android:src="@drawable/left" />
<TextView
android:id="@+id/tv_leftBluetooth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="Not Connected"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_rightBattery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="100%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/holo_red_dark"
android:textSize="16sp"
android:visibility="gone" />
<ImageView
android:id="@+id/imgRightBluetooth"
android:layout_width="wrap_content"
android:layout_height="@dimen/title_img_width"
android:layout_marginTop="5dp"
android:src="@drawable/right" />
<TextView
android:id="@+id/tv_rightBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="Not Connected"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="@dimen/menu_tital_padding" >
<ToggleButton
android:id="@+id/toggleButton_connectBluetooth"
android:layout_width="@dimen/title_img_height"
android:layout_height="@dimen/title_text_height"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/toggle_selector"
android:checked="false"
android:padding="5dp"
android:text=""
android:textOff=""
android:textOn="" />
<TextView
android:id="@+id/tv_toggle_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="7dp"
android:text="Connect Left Bluetooths Only"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/fl_balloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="-15dp"
android:gravity="center"
android:visibility="gone" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="@dimen/balloon_width"
android:layout_height="@dimen/balloon_height"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@drawable/balloon" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:fontFamily="Oswald-Regular.ttf"
android:gravity="center"
android:text="Pair"
android:textColor="@android:color/white" />
</FrameLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:fontFamily="Oswald-Regular.ttf"
android:text="Configure Bluetooths"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="@dimen/menu_tital_textsize"
android:visibility="gone" />
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="@dimen/menu_top_icon"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="29dp"
android:background="@drawable/button_box"
android:padding="3dp"
android:text="Continue"
android:textColor="@android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</RelativeLayout>
進行了點擊的ID是 imgLeftBluetooth和imgRightBluetooth。這兩個圖像瀏覽僅在第二次點擊後觸發。
爲什麼你使用imgLeft.setOnFocusChangeListener(新View.OnFocusChangeListener()什麼的reaaon @迪內希拉維 – YUVRAJ
是大的圖像或類似按鈕做你的ImageButton – Pavan
@murugalonger嘗試我在其他一些鋸stackoverfow帖子。我現在無法完成。在那裏提到使用setonFocusListener和onClickListener。 –