0

I'm learning about Android Wear and I have to do a listView with custom layout.

I have this code for each item view of ListView with linearLayout.

<br.com.mobills.wear.views.WearableListItemLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
app:layout_box="all"
android:layout_height="match_parent">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="15dp"
    android:orientation="vertical">
    <TextView
        android:id="@+id/title"
        android:gravity="center_vertical|left"
        android:layout_width="wrap_content"
        android:layout_marginRight="16dp"
        android:layout_height="wrap_content"
        android:text="@string/contas_title"
        android:fontFamily="sans-serif-condensed-light"
        android:textColor="@color/white"
        android:textSize="14sp"/>

    <TextView
        android:id="@+id/subtitle"
        android:gravity="center_vertical|left"
        android:layout_width="wrap_content"
        android:layout_marginRight="16dp"
        android:layout_height="wrap_content"
        android:text="R$ 25,0000000"
        android:fontFamily="sans-serif-condensed-light"
        android:textColor="@color/white"
        android:textSize="16sp"/>

</LinearLayout>


</br.com.mobills.wear.views.WearableListItemLayout>

list_item.xml

But when I populate my adapter this happens:

ListView Populate

Does anybody know how to fix this?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Igor Ronner
  • 1,565
  • 2
  • 14
  • 31

2 Answers2

1

In many cases, each list item consists of an icon and a description. The Notifications sample implements a custom layout that extends LinearLayout to incorporate these two elements inside each list item. This layout also implements the methods in the WearableListView.OnCenterProximityListener interface to change the color of the item's icon and fade the text in response to events from the WearableListView element as the user scrolls through the list.

public class WearableListItemLayout extends LinearLayout
             implements WearableListView.OnCenterProximityListener {

    private ImageView mCircle;
    private TextView mName;

    private final float mFadedTextAlpha;
    private final int mFadedCircleColor;
    private final int mChosenCircleColor;

    public WearableListItemLayout(Context context) {
        this(context, null);
    }

    public WearableListItemLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public WearableListItemLayout(Context context, AttributeSet attrs,
                                  int defStyle) {
        super(context, attrs, defStyle);

        mFadedTextAlpha = getResources()
                         .getInteger(R.integer.action_text_faded_alpha) / 100f;
        mFadedCircleColor = getResources().getColor(R.color.grey);
        mChosenCircleColor = getResources().getColor(R.color.blue);
    }

    // Get references to the icon and text in the item layout definition
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        // These are defined in the layout file for list items
        // (see next section)
        mCircle = (ImageView) findViewById(R.id.circle);
        mName = (TextView) findViewById(R.id.name);
    }

    @Override
    public void onCenterPosition(boolean animate) {
        mName.setAlpha(1f);
        ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
    }

    @Override
    public void onNonCenterPosition(boolean animate) {
        ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
        mName.setAlpha(mFadedTextAlpha);
    }
}

For more information, check this document: https://developer.android.com/training/wearables/ui/lists.html

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
0

This code works for me!

<br.com.mobills.wear.views.WearableListItemLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center_vertical|center_horizontal"
    android:layout_width="match_parent"
    android:layout_gravity="center_vertical"
    android:weightSum="2"
    app:layout_box="top|bottom"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:padding="8dp"
        android:background="@drawable/circle_blue"
        android:src="@drawable/ic_credit_card_white_24dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

            <TextView
                android:id="@+id/title"
                android:gravity="left"
                android:layout_height="wrap_content"
                android:text="adsfdsfasdfasdfasf sdf asdf asdf "
                android:maxLines="1"
                android:ellipsize="end"
                android:fontFamily="sans-serif-condensed-light"
                android:textColor="@color/white"
                android:textSize="14sp"
                android:layout_width="match_parent" />

            <TextView
                android:id="@+id/subtitle"
                android:gravity="left"
                android:layout_height="wrap_content"
                android:maxLines="1"
                android:text="R$1000000"
                android:fontFamily="sans-serif-condensed-light"
                android:textColor="@color/white"
                android:textSize="24sp"
                android:textStyle="normal|bold"
                android:layout_width="match_parent" />

    </LinearLayout>

This is the result

Igor Ronner
  • 1,565
  • 2
  • 14
  • 31