本文介绍了如何设置WearableListView项目高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做WearableListView名单。问题是,Android的设置:layout_height =20dp没有帮助

如何设置高度在这种情况下?在Android Wear样本项目的通知和定时器他们也只是设置属性附加伤害机器人:layout_height =80dp。但我想在Android的项目设置:layout_height =20dp,但它并没有帮助! (下面是我的项目源$ C ​​$ C):

list_item.xml:

 <?XML版本=1.0编码=UTF-8&GT?;
< base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =20dp
    机器人:重力=center_vertical>    <的TextView
        机器人:ID =@ + ID / text_hole
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:fontFamily中=无衬线光
        机器人:比重=中心
        机器人:TEXTSIZE =@扪/ list_item_text_size/>
< /base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout>

HolesListItemLayout.java:

公共类HolesListItemLayout扩展的LinearLayout
        实现WearableListView.OnCenterProximityListener {
    私人TextView的MNAME;
    私人最终诠释mFadedTextColor;
    私人最终诠释mChosenTextColor;

 公共HolesListItemLayout(上下文的背景下){
    这(背景下,NULL);
}公共HolesListItemLayout(上下文的背景下,ATTRS的AttributeSet){
    这(背景下,ATTRS,0);
}公共HolesListItemLayout(上下文的背景下,ATTRS的AttributeSet,
                           INT defStyle){
    超(背景下,ATTRS,defStyle);
    mFadedTextColor = getResources()的getColor(R.color.grey)。
    mChosenTextColor = getResources()的getColor(R.color.black)。
}//获取在项目布局定义图标和文本引用
@覆盖
保护无效onFinishInflate(){
    super.onFinishInflate();
    MNAME =(的TextView)findViewById(R.id.text_hole);
}@覆盖
公共无效onCenterPosition(布尔动画){
    mName.setTextSize(18);
    mName.setTextColor(mChosenTextColor);
}@覆盖
公共无效onNonCenterPosition(布尔动画){
    mName.setTextColor(mFadedTextColor);
    mName.setTextSize(14);
}

}

HolesListAdapter.java:

 公共类HolesListAdapter扩展WearableListView.Adapter {
    私人最终上下文mContext;
    私人最终LayoutInflater mInflater;    公共HolesListAdapter(上下文的背景下){
        this.mContext =背景;
        mInflater = LayoutInflater.from(上下文);
    }    @覆盖
    公共WearableListView.ViewHolder onCreateViewHolder(ViewGroup中的父母,INT viewType){
        返回新WearableListView.ViewHolder(
                mInflater.inflate(R.layout.list_item_hole,NULL));
    }    @覆盖
    公共无效onBindViewHolder(WearableListView.ViewHolder持有人,INT位置){
        TextView的文本=(TextView的)holder.itemView.findViewById(R.id.text_hole);
        text.setText(mContext.getString(R.string.hole_list_item)++(位置+ 1));
        text.setTextColor(mContext.getResources()的getColor(android.R.color.black));
        holder.itemView.setTag(位置);
    }    @覆盖
    公众诠释getItemCount(){
        返回preferences.HOLES;
    }
}


解决方案

该WearableListView是硬codeD只显示三个项目在一个时间 - 它由除以三列表视图的高度测量项目的高度.. ,所以没有做你想要什么的一条可行之路。

我建议把文本字体更大...

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

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;
    }
}
解决方案

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 ...

这篇关于如何设置WearableListView项目高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:53