如何使用%?在LinearLayout上放置ImageView?
问题描述:
我想在Android的创造是这样的:如何使用%?在LinearLayout上放置ImageView?
我目前的做法是设法创建一个LinearLayout中,并用不同的权重的一些看法吧。这工作得很好:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/market_bar"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:background="@android:color/holo_red_light"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:background="@android:color/holo_green_dark"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
但现在如何添加图像中出现的标记?我不认为我可以用重量来实现这一点。例如,如何将标记放置在条的最后?
谢谢
答
我改变了一个带有FrameLayout的LinearLayout来改进代码。
这是图形布局:
这是代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/actual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="40dp"
android:text="Actual" />
<FrameLayout
android:id="@+id/market_bar"
android:layout_width="match_parent"
android:layout_below="@id/actual"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:background="@android:color/holo_red_light" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:background="@android:color/holo_green_dark" />
</LinearLayout>
</FrameLayout>
<TextView
android:id="@+id/apertura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/market_bar"
android:layout_alignParentLeft="true"
android:paddingLeft="120dp"
android:text="Apertura" />
</RelativeLayout>
我建议你也来检查此链接:
http://developer.android.com/guide/topics/ui/layout/relative.html
答
我没有如果你想建立一个静态视图或者像交互式双滑块那样的东西,就可以得到它。 顺便说一下,考虑到第一种情况,您可以通过调整android:layout_marginLeft
来移动标记。
根据您的代码示例:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/market_bar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<View
android:layout_width="10dp"
android:layout_height="20dp"
android:background="@android:color/holo_orange_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp">
<View
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_weight="0.2"
android:background="@android:color/holo_red_light"/>
<View
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_weight="0.8"
android:background="@android:color/holo_green_dark"/>
</LinearLayout>
<View
android:layout_width="10dp"
android:layout_height="20dp"
android:layout_marginLeft="310dp"
android:background="@android:color/holo_orange_dark"/>
</LinearLayout>
</RelativeLayout>
使用farmelayout你的基地布局。 – 2014-11-03 23:31:02