I have 3 ImageButtons
in my view. One of them has a drawable in the src
which works. When I add the src
to the other two the app crashes when I tap the same button that had the image at first.
Here is the code below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="0px"
android:paddingRight="0px"
android:paddingTop="0px"
android:paddingBottom="0px" tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="400px"
android:id="@+id/relativeLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="500px"
android:background="#2196F3"
android:id="@+id/topRowBackground"/>
<ImageButton
android:layout_width="80px"
android:layout_height="80px"
android:layout_marginLeft="20px"
android:layout_marginTop="20px"
android:id="@+id/logOut"
android:background="@android:color/transparent"
android:shadowColor="@android:color/transparent"
android:layout_weight="1"
android:src="@drawable/log_out"
android:scaleType="fitStart"/>
<ImageView
android:layout_width="100px"
android:layout_height="100px"
android:layout_centerHorizontal="true"
android:layout_marginTop="100px"
android:background="@android:color/transparent"
android:shadowColor="@android:color/transparent"
android:layout_weight="1"
android:src="@drawable/user_icon"
android:scaleType="fitStart"/>
<TextView
android:text="[username]"
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#1b1b1b"
android:textSize="60px"
android:layout_marginTop="240px"/>
<TextView
android:text="Points: [points]"
android:id="@+id/points"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#1b1b1b"
android:textSize="60px"
android:layout_marginTop="350px"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/topRowBackground"
android:weightSum="3"
android:orientation="vertical"
android:background="#1b1b1b">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="vertical"
android:background="#ff1b1b1b"
android:id="@+id/challengeLayout">
<ImageButton
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_centerVertical="true"
android:id="@+id/challengeIcon"
android:background="@android:color/transparent"
android:shadowColor="@android:color/transparent"
android:layout_weight="1"
android:src="@drawable/challenge_icon"
android:layout_gravity="center|bottom"
android:padding="10dp"
android:scaleType="fitCenter"/>
<Button
android:id="@+id/challengeButton"
android:layout_width="match_parent"
android:text="Challenge"
android:background="#1B1B1B"
android:shadowColor="@android:color/transparent"
android:textColor="#2196F3"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="18dp"
android:scaleType="fitCenter"
android:gravity="center_horizontal|top"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="vertical"
android:background="#1B1B1B"
android:id="@+id/leaderboardLayout">
<ImageView
android:id="@+id/leaderboardIcon"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:layout_gravity="center|bottom"
android:padding="10dp"
android:background="@android:color/transparent"
android:shadowColor="@android:color/transparent"
android:layout_margin="12px"
android:src="@drawable/leaderboard_icon"/>
<Button
android:id="@+id/leaderboardButton"
android:layout_width="match_parent"
android:text="Leaderboard"
android:background="#1B1B1B"
android:shadowColor="@android:color/transparent"
android:textColor="#2196F3"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="18dp"
android:scaleType="fitCenter"
android:gravity="center_horizontal|top"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="2"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="vertical"
android:background="#1B1B1B"
android:id="@+id/storeLayout">
<ImageButton
android:id="@+id/storeIcon"
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:layout_gravity="center|bottom"
android:padding="10dp"
android:background="@android:color/transparent"
android:shadowColor="@android:color/transparent"
android:src="@drawable/store_icon"
/>
<Button
android:id="@+id/storeButton"
android:layout_width="match_parent"
android:text="Store"
android:background="#1B1B1B"
android:shadowColor="@android:color/transparent"
android:textColor="#2196F3"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="18dp"
android:scaleType="fitCenter"
android:gravity="center_horizontal|top"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
The issue seems to have been that my image files were too large. Once I decreased their size the app started to perform as expected.