Reputation: 31
I'm working on a project for a cookbook recipe app. The issue I'm facing is that when I enter the description for the recipe in the app. The icon moves with the text. Is there a way to fix the icon at a specific position in the layout using xml or code in the activity?
Here is a picture of the problem:
<android.support.v7.widget.CardView
android:id="@+id/cardViewList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="18sp"
android:textStyle="bold" />
<TableRow
android:id="@+id/trPersonsTimeDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_alignParentLeft="true"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/recipe_icon"
android:layout_width="33dp"
android:layout_height="match_parent"
android:background="@drawable/recipe_1" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beschreibung"
android:textSize="16dp" />
</TableRow>
<TableRow
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/trPersonsTimeDetails"
android:layout_alignParentLeft="true"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/time"
android:layout_width="33dp"
android:layout_height="33dp"
android:background="@drawable/timer" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/trPersonsTimeDetails"
android:text="Zeit"
android:textSize="16dp" />
</TableRow>
</RelativeLayout>
</android.support.v7.widget.CardView>
Upvotes: 0
Views: 73
Reputation: 2829
For imageView you should use parameter src
instead of background
and for the scaling issue you need scaleType="fitCenter"
just like this:
<ImageView
android:id="@+id/recipe_icon"
android:layout_width="33dp"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/recipe_1" />
Upvotes: 2
Reputation: 538
you could just set a defined size to 24dp x 24dp and change the scaletype to fit center
Upvotes: 2