问题描述
这似乎是一个很无聊的问题,但它只是不为我工作。
This seems to be a very silly problem but its just not working for me.
我有2个ImageButtons&安培;页面上的HorizontalScrollView(HSV)。奇怪的图像按钮(第一个)的一个不点击。此外,我想使HSV点击所以我用:
I have 2 ImageButtons & a HorizontalScrollView(HSV) on a page. Strangely one of the Image Button(1st one) is not clicking. Also I wanted to make the HSV clickable so I used:
的android:点击=真正的
,它不能正常工作
您可以使用XML和放大器;活动正是因为我已经发布。
You can use the xml & activity exactly as I have posted.
这是XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/topRL"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/free_msgs_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="free msgs left" />
<ImageButton
android:id="@+id/buy_imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher"
/>
</RelativeLayout>
<ListView
android:id="@+id/chat_page_listView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<HorizontalScrollView
android:id="@+id/chat_message_HSV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="@+id/send_image_button"
android:clickable="true" />
<ImageButton
android:id="@+id/send_image_button"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
这是该活动文件:
public class MainActivity extends Activity {
ImageButton buyIB;
ImageButton sendIB;
HorizontalScrollView chatMessageHSV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
sendIB = (ImageButton) findViewById(
R.id.send_image_button);
chatMessageHSV = (HorizontalScrollView) findViewById(
R.id.chat_message_HSV);
buyIB = (ImageButton) findViewById(R.id.buy_imageButton);
buyIB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "buy", Toast.LENGTH_SHORT)
.show();
}
});
chatMessageHSV.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "hsv", Toast.LENGTH_SHORT).show();
}
});
sendIB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "send", Toast.LENGTH_SHORT).show();
}
});
}// end of onCreate
}
和我不能使用按钮点击像
And I cant use button click like
public void onClick(View view)
{}
由于实际的问题是包含一个抽屉布局在那里我用片段放;有这种方法是行不通的。
because the actual problem is containing a drawer layout where I'm using fragments & there this method doesn't work.
推荐答案
的的ImageButton
不为你在回应这个问题点击,因为的ListView
将首先用于点击反应,因为它上面的的ImageButton
尝试重新订购吧,当我删除了的ImageButton
的点击响应
The problem in the ImageButton
doesn't respond for you click because the ListView
will respond first for the click because it above the ImageButton
try to re order it , when i remove it the ImageButton
respond for the click
有关 HorizontallScrollView
我发现使用触摸事件的解决方案
而不是的点击
试试这个code
about the HorizontallScrollView
i found the solution to use the Touch Event
instead of Click
try this code
chatMessageHSV.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Toast.makeText(ImageButtonActivity.this, "hsv",
Toast.LENGTH_SHORT).show();
}else if (event.getAction() == MotionEvent.ACTION_UP){
// here code if the touch up
}
return false;
}
});
喂我回来
这篇关于其中的ImageButton不点击和放大器;使HorizontalScrollView点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!