thank you for the project. It would be better if you send it zipped next time. Anyway, I managed to resolve your issue and now Image Button is clickable. The problem was with your Horizontal Scroll View, it covered all the screen so it was impossible to click on a button. This is working xml file of Main Activity:
<?xml version="1.0" encoding="utf-8"?><ScrollView 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:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.AndamanTravelGuide.ravi.AndamanTravelGuide.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="7dp"
app:srcCompat="@drawable/logo"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="175dp"
android:layout_height="200dp"
android:layout_below="@+id/imageView"
android:layout_marginLeft="7dp"
android:layout_marginTop="8dp"
app:srcCompat="@drawable/beaches"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="175dp"
android:layout_height="200dp"
android:layout_alignTop="@+id/imageButton"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_toEndOf="@+id/imageButton"
android:layout_toRightOf="@+id/imageButton"
app:srcCompat="@drawable/sight"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="175dp"
android:layout_height="200dp"
android:layout_alignLeft="@+id/imageButton"
android:layout_alignStart="@+id/imageButton"
android:layout_below="@+id/imageButton"
android:layout_marginTop="7dp"
app:srcCompat="@drawable/events"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="175dp"
android:layout_height="200dp"
android:layout_alignLeft="@+id/imageButton2"
android:layout_alignStart="@+id/imageButton2"
android:layout_alignTop="@+id/imageButton3"
android:layout_marginRight="7dp"
app:srcCompat="@drawable/museums"
tools:ignore="ContentDescription,RtlHardcoded" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageButton3"
android:layout_marginLeft="7dp"
android:layout_marginTop="10dp"
android:text="@string/ferries_in_andaman"
android:textSize="16dp"
tools:ignore="RtlHardcoded,SpUsage" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarSize="0dp"
android:layout_alignTop="@+id/textView2">
<LinearLayout
android:layout_width="1028dp"
android:layout_height="145dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="515dp"
android:orientation="horizontal"
tools:ignore="RtlHardcoded">
<ImageButton
android:id="@+id/makruzzButton"
android:layout_width="200dp"
android:layout_height="145dp"
android:layout_marginLeft="0dp"
app:srcCompat="@drawable/makk"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/greenoceanButton"
android:layout_width="200dp"
android:layout_height="145dp"
android:layout_marginLeft="7dp"
app:srcCompat="@drawable/green"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/coastalButton"
android:layout_width="200dp"
android:layout_height="145dp"
android:layout_marginLeft="7dp"
app:srcCompat="@drawable/coastal"
tools:ignore="ContentDescription" />
<ImageButton
android:id="@+id/govtferryButton"
android:layout_width="200dp"
android:layout_height="145dp"
android:layout_marginLeft="7dp"
app:srcCompat="@drawable/govt"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/makruzzgoldButton"
android:layout_width="200dp"
android:layout_height="145dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
app:srcCompat="@drawable/gold"
tools:ignore="ContentDescription,InefficientWeight" />
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="665dp"
android:text="@string/water_sports_and_other_activities"
android:textSize="16dp"
tools:ignore="RtlHardcoded,SpUsage" />
<ImageButton
android:id="@+id/watersportsButton"
android:layout_width="175dp"
android:layout_height="175dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="695dp"
app:srcCompat="@drawable/scuba"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/activitiesButton"
android:layout_width="175dp"
android:layout_height="175dp"
android:layout_alignTop="@+id/watersportsButton"
android:layout_marginLeft="189dp"
android:layout_marginRight="7dp"
app:srcCompat="@drawable/activities"
tools:ignore="ContentDescription,RtlHardcoded" />
<TextView
android:id="@+id/watersportsTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="871dp"
android:text="@string/watersports"
android:textSize="14dp"
tools:ignore="RtlHardcoded,SpUsage" />
<TextView
android:id="@+id/activitiesTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="189dp"
android:layout_marginTop="871dp"
android:text="@string/activities"
android:textSize="14dp"
tools:ignore="RtlHardcoded,SpUsage" />
<TextView
android:id="@+id/HRtextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="895dp"
android:text="@string/hotels_and_restaurants"
android:textSize="16dp"
tools:ignore="RtlHardcoded,SpUsage" />
<ImageButton
android:id="@+id/hotelButton"
android:layout_width="175dp"
android:layout_height="175dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="925dp"
app:srcCompat="@drawable/hotels"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/restaurantButton"
android:layout_width="175dp"
android:layout_height="175dp"
android:layout_marginLeft="189dp"
android:layout_marginRight="7dp"
android:layout_marginTop="925dp"
app:srcCompat="@drawable/restaurant"
tools:ignore="ContentDescription,RtlHardcoded" />
<TextView
android:id="@+id/restaurantsTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:layout_marginLeft="189dp"
android:layout_marginTop="1100dp"
android:text="@string/restaurants"
android:textSize="14dp"
tools:ignore="RtlHardcoded,SpUsage" />
<TextView
android:id="@+id/hotelsTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="1100dp"
android:text="@string/hotels"
android:textSize="14dp"
tools:ignore="RtlHardcoded,SpUsage" />
<ImageButton
android:id="@+id/generalButton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="1125dp"
app:srcCompat="@drawable/generall"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/emergencyButton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="96dp"
android:layout_marginTop="1125dp"
app:srcCompat="@drawable/emergencyy"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/bankButton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="195dp"
android:layout_marginTop="1125dp"
app:srcCompat="@drawable/bank"
tools:ignore="ContentDescription,RtlHardcoded" />
<ImageButton
android:id="@+id/aboutButton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="280dp"
android:layout_marginTop="1125dp"
app:srcCompat="@drawable/about"
tools:ignore="ContentDescription,RtlHardcoded" />
<TextView
android:id="@+id/InformationtextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="1205dp"
android:text="@string/information"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/EmergencytextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="105dp"
android:layout_marginTop="1205dp"
android:text="@string/emergency"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/banktextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="220dp"
android:layout_marginTop="1205dp"
android:text="@string/banks"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/abouttextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="295dp"
android:layout_marginRight="7dp"
android:layout_marginTop="1205dp"
android:text="@string/about_us"
tools:ignore="RtlHardcoded" />
</RelativeLayout>
</ScrollView
You can do with you want when the button is clicked inside this method:
ImageButton myImageButton = (ImageButton) findViewById(R.id.imageButton);
myImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "clicked", Toast.LENGTH_LONG).show();
Intent beach = new Intent(MainActivity.this, beachActivity.class);
startActivity(beach);
}
});
If you have any questions, feel free to ask!
— modified on Apr 14, 2017, 1:53:06 PM