我想在图像中获得渐变条 我有渐变条但是如何在渐变条上获得25%,50%
的白线 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:width="1dp"
android:color="#2B2B2D" >
</solid>
<stroke
android:width="1dp"
android:color="#666666" >
</stroke>
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" >
</padding>
<corners
android:radius="2dp" >
</corners>
</shape>
</item>
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" >
</padding>
<corners
android:radius="2dp" >
</corners>
<gradient
android:angle="180"
android:endColor="#11B24A"
android:centerColor="#fec804"
android:startColor="#E3434B"
android:type="linear" />
</shape>
</item>
</layer-list>
我使用上面的代码作为imageview的背景 我可以使用高度为8dp且宽度为1dp的视图来获取线条如何将它们放置在25%50%的正确位置。
答案 0 :(得分:1)
我有一种hacky方式:
代码:
gradient_bar.xml(与你的相同)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<View
android:layout_width="1dp"
android:layout_margin="2dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:background="@android:color/white"/>
</RelativeLayout>
white_line.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<View
android:layout_width="1dp"
android:layout_margin="2dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"/>
</RelativeLayout>
<小时/> no_white_line.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/gradient_bar"
android:layout_centerVertical="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="10dp"
android:orientation="horizontal"
android:layout_centerVertical="true">
<include layout="@layout/white_line"/>
<include layout="@layout/white_line"/>
<include layout="@layout/white_line"/>
<include layout="@layout/white_line"/>
<include layout="@layout/no_white_line"/>
</LinearLayout>
</RelativeLayout>
activity_main.xml中
cd directory
gsed -i 's/"myValue":"[0-9]\+"/"myValue":"57"/g' *
输出:
<小时/> 希望它有所帮助!