具有自定义WearableListItemLayout的WearableListView不显示内容

时间:2016-12-14 13:17:36

标签: android wear-os android-wear-2.0

我正在学习Android Wear,我必须使用自定义布局listView

对于ListView 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

但是当我填充我的适配器时,会发生这种情况:

ListView Populate

有人知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

在许多情况下,每个列表项都包含一个图标和一个描述。 Notifications示例实现了一个自定义布局,该布局扩展了LinearLayout,以便在每个列表项中包含这两个元素。此布局还实现了WearableListView.OnCenterProximityListener界面中的方法,以便在用户滚动列表时更改项目图标的颜色并淡化文本以响应来自WearableListView元素的事件。

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);
    }
}

有关详情,请查看此文档:https://developer.android.com/training/wearables/ui/lists.html

答案 1 :(得分:0)

此代码适合我!

Ecto.Changeset.change(user, password: "changeme")

This is the result