Android 为什么要到最后一次?
我在expandableListView中有一个包含此列表子项的xmlAndroid 为什么要到最后一次?,android,xml,uiimageview,onclick,expandablelistview,Android,Xml,Uiimageview,Onclick,Expandablelistview,我在expandableListView中有一个包含此列表子项的xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp" >
<ImageView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_clock"
android:paddingLeft="30dp"
android:contentDescription="@string/app_name"
android:onClick="goMap"/>
<ImageView
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_map"
android:paddingLeft="105dp"
android:contentDescription="@string/app_name"
android:onClick="goSchedule"/>
</RelativeLayout>
并在两个ImageView中输入最后一个OnClick。为什么?
感谢您在RelativeLayout中为两个图像视图使用paddingLeft。因此,第二个ImageView超过了第一个。虽然您同时看到两个视图,但第二个视图位于第一个视图之上。使用layout_marginLeft属性而不是paddingLeft
这是因为您没有正确对齐图像视图。 这样做:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp" >
<ImageView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_marginRight="20dp"
android:contentDescription="@string/app_name"
android:onClick="goMap"/>
<ImageView
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_toRightOf="@+id/clock"
android:contentDescription="@string/app_name"
android:onClick="goSchedule"/>
</RelativeLayout>
您能解释一下您的问题吗?您的意思是两个ImageView都使用相同的onClick方法,即goSchedule()?请发布您的代码…public void goSchedule(View-View){Intent i=new Intent(this,TimeTableActivity.class);this.startActivity(i);}
为什么不实用地使用onClicklistener呢?好的,非常感谢。你是对的。如果我想在两个imageView之间留出更多空间,请在imageView中添加marginLeft或marginRight。请尝试我编辑过的答案。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp" >
<ImageView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_marginRight="20dp"
android:contentDescription="@string/app_name"
android:onClick="goMap"/>
<ImageView
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_toRightOf="@+id/clock"
android:contentDescription="@string/app_name"
android:onClick="goSchedule"/>
</RelativeLayout>