2015-08-10 18 views
8

Tôi tạo danh sách WearableListView. Vấn đề là cài đặt android: layout_height = "20dp" không giúp được enter image description hereCách đặt chiều cao mục WearableListView

Cách đặt chiều cao trong trường hợp này? Trong các dự án mẫu Android Wear Thông báo và hẹn giờ, họ cũng chỉ đặt thuộc tính android: layout_height = "80dp". Nhưng tôi đã cố gắng để thiết lập trong các dự án android: layout_height = "20dp" nhưng nó đã không giúp đỡ! (Dưới đây là mã nguồn dự án của tôi):

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 kéo dài LinearLayout thực hiện WearableListView.OnCenterProximityListener { tin TextView mName; riêng tư cuối cùng int mFadedTextColor; riêng cuối cùng 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; 
    } 
} 

Trả lời

-1

Tôi đã có ý tưởng. Chèn danh sách vào vùng chứa FrameLayout. Và bằng cách thay đổi chiều cao của chiều cao mục danh sách container được thay đổi. Kết quả:

<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

6

Các WearableListView được mã hóa cứng để chỉ hiển thị ba mục tại một thời điểm - đó đo chiều cao mục bằng cách chia chiều cao xem danh sách của ba ... vì vậy không có một cách thực tế để làm những gì bạn muốn.

Tôi đề nghị làm cho font chữ lớn hơn ...

+0

CRUD, di tích này kế hoạch của tôi để sử dụng nó cho màn hình cấu hình của tôi, nhưng nó là tốt để biết. Bây giờ tôi phải đi tìm kiếm lần nữa. – Trejkaz

-1

Thêm một LinearLayout bên trong và thiết lập

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

Các vấn đề liên quan