5

I am using Yuri Kanivets's WheelView control and I am finding that it is not filling the parent view even though the layout XML is specifying it to do so.

Here is an image of what I mean:

enter image description here

Here is the layout XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#00000000">

    <LinearLayout
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:background="@drawable/picker_bar">
            <Button
                android:id="@+id/repeatButton"
                android:textColor="#FFF"                
                android:layout_gravity="center_vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/picker_button_selected"
                android:paddingTop="8dp"
                android:paddingBottom="8dp"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"
                android:layout_marginLeft="7dp"
                android:gravity="center"
                android:textSize="16sp"
                android:text="Repeat"/>
            <Button
                android:id="@+id/DelayButton"
                android:layout_gravity="center_vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/picker_button_unselected"
                android:paddingTop="8dp"
                android:textColor="#FFF"
                android:paddingBottom="8dp"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"  
                android:layout_marginLeft="10dp"  
                android:gravity="center"
                android:textSize="16sp"         
                android:text="Delay"/>
            <Button
                android:id="@+id/doneButton"
                android:layout_marginLeft="10dp"
                android:layout_gravity="center_vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/picker_button_unselected"
                android:textColor="#FFF"
                android:paddingTop="8dp"
                android:paddingBottom="8dp"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"
                android:gravity="center"
                android:textSize="16sp"
                android:text="Done"/>               
        </LinearLayout>

        <include layout="@layout/repeat_view"/>
        <include layout="@layout/delay_view"/>
   </LinearLayout>
</RelativeLayout>

Here is the repeat/delay view XML (they are both pretty much the same):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/wheelRepeat"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="@drawable/layout_bg"
    android:layout_width="fill_parent">
    <LinearLayout 
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_width="fill_parent"
        android:paddingTop="4dp"
        android:paddingBottom="4dp"     
        android:orientation="horizontal">
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/activeRepeat"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"/>             
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/minsRepeat"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"/>
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/secsRepeat"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"/>                 
    </LinearLayout>
</LinearLayout>

Here is how I'm adding the view:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.settings);

            ...

I've looked through the WheelView source, but it's not obvious where the width of the entire control is being set and if the wheel control is somehow also controlling the width of the parent layout.

This is running on the latest SDK. Is there something obvious that I am missing?

4

4 回答 4

6

其中LinearLayout包含三个desiderata.ihunt.resources.WheelViewandroid:layout_width="fill_parent",但 WheelViews 本身有:

android:layout_height="wrap_content"
android:layout_width="wrap_content"

话虽这么说,如果我正确理解了这个问题的意思,如果三个轮子的宽度小于parent(在这种情况下LinearLayout包含三个轮子)的宽度desiderata.ihunt.resources.WheelView- 那么你将不得不拉伸填充轮子用LinearLayout纯色(例如黑色)来隐藏它背后的东西。

于 2013-06-28T07:35:53.233 回答
1

g00dy 的替代解决方案(尽管他完全正确)- 如果将每个轮子的宽度设置为 0dp 并设置它们的 layout_weight=1,则 3 将拉伸以占据屏幕的相等部分。如果您不希望它们相等,请将它们设置为您想要的比率。

于 2013-07-01T10:34:24.450 回答
0
 <LinearLayout 
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_width="fill_parent"
        android:paddingTop="4dp"
        android:weightSum="3"      // add weight sum here 
        android:paddingBottom="4dp"     
        android:orientation="horizontal">
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/activeRepeat"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"/>             //weights here
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/minsRepeat"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"/>              //weights here
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/secsRepeat"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"/>              //weights here    
    </LinearLayout>

像这样改变你的轮子布局

于 2013-07-01T10:38:40.210 回答
0

为您的重复/延迟视图 xml 尝试这样的布局

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/wheelRepeat"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="@drawable/layout_bg"
    android:layout_width="fill_parent">
    <LinearLayout 
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_width="fill_parent"
        android:paddingTop="4dp"
        android:paddingBottom="4dp"     
        android:orientation="horizontal"
        android:weightSum="10">

       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/activeRepeat"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="2"/>             
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/minsRepeat"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="4"/>
       <desiderata.ihunt.resources.WheelView 
            android:id="@+id/secsRepeat"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="4"/>                 
    </LinearLayout>
</LinearLayout>

这将使小部件填充屏幕宽度,您可以通过调整布局权重来调整宽度比例。如果您不需要小部件在横向模式下填充整个屏幕,您可以使用 wrap content 作为父线性布局的宽度。

于 2013-07-01T12:14:39.660 回答