Я работаю над макетом Constraint, в котором есть две кнопки изображения с разными идеями, расположенными рядом друг с другом, например:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- here are some views -->
<ImageButton
android:id="@+id/openCamera"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:clickable="true"
android:contentDescription="@string/camera_button"
android:focusable="true"
android:scaleX="3.7"
android:scaleY="3.7"
android:adjustViewBounds="true"
app:layout_constraintBottom_toTopOf="@id/text"
app:layout_constraintEnd_toStartOf="@id/openGallery"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/logoText"
app:srcCompat="@drawable/ic_camera_icon" />
<ImageButton
android:id="@+id/openGallery"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:adjustViewBounds="true"
android:clickable="true"
android:contentDescription="@string/gallery_button"
android:focusable="true"
android:scaleX="3.7"
android:scaleY="3.7"
app:layout_constraintBottom_toTopOf="@id/text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/openCamera"
app:layout_constraintTop_toBottomOf="@id/logoText"
app:srcCompat="@drawable/ic_gallery_icon" />
<!-- other views -->
</android.support.constraint.ConstraintLayout>
проблема в том, что когда я нажимаю кнопки эфира, я получаю id второй кнопки (например, когда я меняю их положение, я всегда получаю вторую id ).
как я могу решить эту проблему?
- я попытался:
не реализован интерфейс View.OnClickListener
и проверил, что по-прежнему возникает та же проблема.
Я работал над относительным макетом, но у него была большая иерархия, поэтому я переключился на макет ограничения.
код Java:
@Override
protected void onCreate(Bundle savedInstanceState) {
ImageButton openCameraButton = (ImageButton) findViewById(R.id.openCamera);
ImageButton openGalleryButton = (ImageButton) findViewById(R.id.openGallery);
openCameraButton.setOnClickListener(this);
openGalleryButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.openCamera:
someMethod();
break;
case R.id.openGallery:
antherMethod();
break;
default:
Log.v(TAG, "HOW YOU GET THERE!!!");
break;
}
}
чтоя получаю из режима отладки: введите описание изображения здесь