2016-12-14 4 views
0

Ich lerne über Android Wear und ich muss eine listView mit benutzerdefinierten Layout zu tun.WearableListView mit benutzerdefinierten WearableListItemLayout zeigen keinen Inhalt

Ich habe diesen Code für jede Artikelansicht von ListView mit 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

Aber wenn ich mein Adapter bevölkern das geschieht:

ListView Populate

Weiß jemand, wie man das Problem lösen?

Antwort

1

In vielen Fällen besteht jedes Listenelement aus einem Symbol und einer Beschreibung. Das Beispiel Notifications implementiert ein benutzerdefiniertes Layout, das LinearLayout so erweitert, dass diese beiden Elemente in jedem Listenelement enthalten sind. Dieses Layout implementiert auch die Methoden in der Schnittstelle WearableListView.OnCenterProximityListener, um die Farbe des Symbols des Elements zu ändern und den Text als Reaktion auf Ereignisse aus dem Element WearableListView auszublenden, während der Benutzer durch die Liste scrollt.

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

Für weitere Informationen lesen Sie in diesem Dokument: https://developer.android.com/training/wearables/ui/lists.html

0

Dieser Code funktioniert für mich!

<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