I'm working on a layout for WearOS and I am having trouble. I have a ListView, and each row (TextView) of the ListView takes up the entire screen. Now, I want to put an icon on the bottom of of each of the TextViews. My goal is for it to look like the following:
I currently have everything I want besides getting the icon on each row. I have imported it, I just don't know how to define the XML. I tried other StackOverFlow questions, but I couldn't get them to work. I am also confident in my custom adapter. It is the layouts that is giving me trouble. I am new to layouts, so it is definitely my failure to understand them that is giving me trouble. I tried following tutorials that explain how Android layouts work but I am just not getting them for some reason.
The XML for the ListView is:
<?xml version="1.0" encoding="utf-8"?>
<!-- Defines the layout for the ListView-->
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/goals_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</android.support.constraint.ConstraintLayout>
And the XML for each row of the ListView is:
<?xml version="1.0" encoding="utf-8"?>
<!-- Defines the layout for a row in the ListView-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<TextView
android:id="@+id/goal_row"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/info_icon"
/>
</LinearLayout>
I want to use these layouts, so please try to help me with what I already have. If you have suggestions on a different way to do what I am trying to do, I am open to suggestions but this is how I am going to implement it. Thank you for any help.
Try the following:
<?xml version="1.0" encoding="utf-8"?>
<!-- Defines the layout for a row in the ListView-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
>
<TextView
android:id="@+id/goal_row"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello W"
android:layout_above="@id/base"
android:layout_alignParentTop="true"
android:gravity="center"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/icon"
android:layout_above="@id/base"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/base"
android:layout_alignParentBottom="true">
</View>
</RelativeLayout>
Output:-------