我对Android和练习都很陌生。我正在尝试设计一个屏幕。它将包含一个背景图像和一个带滑动菜单的浮动容器。 (有关详细信息,请参阅附图)
我的布局包括一个背景图片,一个带有一些图标的容器,这些图标浮在底部但底部有一些边缘(见附图)
据我所知,这可以通过在底部安排“相对布局”并将图像放入其中来实现。这是对的吗?
此外,我还想添加一个重复的透明图像作为浮动div的背景。
请给我一个很好的建议或指点我一个好的教程
提前致谢
答案 0 :(得分:33)
您可以使用LinearLayout
并将layout_weight设置为xml
对于重复背景,您可以使用tileMode
示例:请注意,weightSum设置为100
,表示总重量为100
。 layout_weight=10
{{}}}将为其分配空间10%
。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="bottom"
android:weightSum="100">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:background="@drawable/bg"
android:orientation="horizontal"
android:tileMode="repeat" >
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5" />
</LinearLayout>
答案 1 :(得分:4)
您可以使用新的百分比支持库实现此目的: https://developer.android.com/tools/support-library/features.html#percent
做这样的事情:
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
app:layout_heightPercent="11%"
app:layout_widthPercent="100%" />
</android.support.percent.PercentRelativeLayout>
答案 2 :(得分:1)
如果你想以百分比划分高度,那么你需要一个水平方向的线性布局,并为每个项目添加layout_weight。
答案 3 :(得分:0)
根据您的要求,任何布局都可以。您也可以通过线性布局实现此目的。 如果我理解您的要求,请查看此讨论。
答案 4 :(得分:0)
<view android:layout_width="wrap_content"
class="net.zel.percentage.PercentageButton"
android:id="@+id/button"
android:layout_height="wrap_content"
customView:percentage_width="50"
customView:percentage_height="50"
/>
因此您可以在库中添加所需的属性 https://github.com/metrolog3005/percentage_view