android:子视图的fill_parent填充屏幕
我正在尝试复制旋转控件(请不要问为什么),我正在与分隔线作斗争。假旋转器看起来很好,直到我将分隔线添加到图像视图的左侧。添加分隔线后,它的高度就会填充屏幕的剩余部分。有人可以解释一下吗?
以下xml:
......
<Spinner
android:id="@+id/equipment_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/spinner_arrow"
android:layout_width="45sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/spinner_arrow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
生成以下屏幕:
添加分隔线后,xml 如下所示:
<Spinner
android:id="@+id/equipment_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/spinner_arrow"
android:layout_width="45sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/spinner_arrow"/>
<View
android:background="#e7ebe7"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/spinner_arrow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
生成以下屏幕:
有人能发现我在这里做错了什么吗?...
I'm trying to replicate a spinner control (please don't ask why) I'm struggling with the divider. The fake spinner looks fine until I add the divider to the left of the imageview. Once I add the divider it's height fills the remaining portion of the screen. Can someone please explain this?
The following xml:
.......
<Spinner
android:id="@+id/equipment_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/spinner_arrow"
android:layout_width="45sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/spinner_arrow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
produces the following screen:
once I add the divider, the xml looks like this:
<Spinner
android:id="@+id/equipment_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/spinner_arrow"
android:layout_width="45sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/spinner_arrow"/>
<View
android:background="#e7ebe7"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/spinner_arrow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
which produces the following screen:
can anyone spot what i'm doing wrong here?...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您应该使用九块图像,而不是使用多个视图。这就是默认 Spinner 的作用。我不知道你为什么要创建一个新的微调器,但如果你保持视觉效果相同,你可以重复使用内置图像。
android.R.layout.simple_spinner_item
是一个可以重用的 TextView 布局。或者,您可以直接获取背景:android.R.drawable.btn_dropdown
,它是一个可绘制的 XML 选择器,其中包含每个状态的位图。更多详细信息请参阅 Android 源代码。You should use a nine-patch image for this instead of using multiple views. That's what the default Spinner does. I don't know why you want to create a new spinner, but if you're keeping the visuals the same you can just reuse the built-in images.
android.R.layout.simple_spinner_item
is a TextView layout you could reuse. Or, you can just take the background directly:android.R.drawable.btn_dropdown
, which is an XML selector drawable with bitmaps for each state. More details are available in the Android source code.您将高度设置为填充父级,该高度将填充相对布局的其余部分。您是否尝试过将视图放入按钮或图像视图中,如下所示:
OR
如果这不起作用,请尝试将相对布局的高度设置为固定值,例如 10 倾角或无论如何旋转器很大...您可能需要尝试一些不同大小的,只是不要将相对布局保留为换行内容
You have the height set to fill parent which fills the remainder of the Relative Layout. Have you tried putting the View inside the button or imageview as follows:
OR
If this doesnt work try setting the height of the relative layout to a fixed amount like 10 dip or however big that spinner is... you may have to try a fiew different sized, just dont leave the relativelayout as wrap content