How to set WearableListView item height
Asked Answered
A

3

8

I make WearableListView list. Problem is that setting android:layout_height="20dp" doesn't help enter image description here

How to set height in this case? In Android Wear sample projects Notifications and Timer they also just set atribute android:layout_height="80dp". But I tried to set in the projects android:layout_height="20dp" but it didn't help! (below is my project source code):

list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:gravity="center_vertical" >

    <TextView
        android:id="@+id/text_hole"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-light"
        android:gravity="center"
        android:textSize="@dimen/list_item_text_size" />
</base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout>

HolesListItemLayout.java:

public class HolesListItemLayout extends LinearLayout implements WearableListView.OnCenterProximityListener { private TextView mName; private final int mFadedTextColor; private final int mChosenTextColor;

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

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

public HolesListItemLayout(Context context, AttributeSet attrs,
                           int defStyle) {
    super(context, attrs, defStyle);
    mFadedTextColor = getResources().getColor(R.color.grey);
    mChosenTextColor = getResources().getColor(R.color.black);
}

// Get references to the icon and text in the item layout definition
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mName = (TextView) findViewById(R.id.text_hole);
}

@Override
public void onCenterPosition(boolean animate) {
    mName.setTextSize(18);
    mName.setTextColor(mChosenTextColor);
}

@Override
public void onNonCenterPosition(boolean animate) {
    mName.setTextColor(mFadedTextColor);
    mName.setTextSize(14);
}

}

HolesListAdapter.java:

public class HolesListAdapter extends WearableListView.Adapter {
    private final Context mContext;
    private final LayoutInflater mInflater;

    public HolesListAdapter(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new WearableListView.ViewHolder(
                mInflater.inflate(R.layout.list_item_hole, null));
    }

    @Override
    public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
        TextView text = (TextView) holder.itemView.findViewById(R.id.text_hole);
        text.setText(mContext.getString(R.string.hole_list_item) + " " + (position + 1));
        text.setTextColor(mContext.getResources().getColor(android.R.color.black));
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return Preferences.HOLES;
    }
}
Araucania answered 10/8, 2015 at 0:48 Comment(0)
P
6

The WearableListView is hard-coded to only display three items at a time - it measures the item height by dividing the list view's height by three ... so there isn't a practical way of doing what you want.

I suggest making the text font larger ...

Phosphorism answered 7/10, 2015 at 11:49 Comment(1)
Crud, this ruins my plans to use it for my config screen, but it's good to know. Now I have to go looking for views again.Faradmeter
A
-1

I've got idea. Insert list into FrameLayout container. And by changing height of container list item height is changed. Result:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:layout_centerInParent="true">

        <android.support.wearable.view.WearableListView
            android:id="@+id/wearable_list_game_options"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:dividerHeight="0dp"
            android:scrollbars="none"/>
    </FrameLayout>

</RelativeLayout>

enter image description here

Araucania answered 10/8, 2015 at 1:59 Comment(0)
F
-1

Add one LinearLayout inside and set

android:layout_height="50dp" android:layout_margin="5dp"

Farlee answered 13/4, 2016 at 7:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.