Vertical line using XML drawable
Instead of a shape, you could try a View
:
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#FF0000FF" />
I have only used this for horizontal lines, but I would think it would work for vertical lines as well.
Use:
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF0000FF" />
for a horizontal line.
How can I create a vertical line in a drawable xml? Android
You could do this by nesting your second item inside a rotate
item.
Android: Draw vertical line in a layout
You can use View
for vertical line instead of a shape:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>
How to draw vertical shape in the centre of XML drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="16dp"
android:left="15px">
<shape
android:shape="rectangle">
<solid android:color="@color/colorAccent" />/>
<size android:width="5dip" />
<stroke android:color="@color/colorAccent" />
</shape>
</item>
<item
android:width="16dp"
android:left="80px">
<shape
android:shape="rectangle">
<solid android:color="@color/colorAccent" />/>
<size android:width="5dip" />
<stroke android:color="@color/colorAccent" />
</shape>
</item>
<item
android:width="16dp"
android:left="140px">
<shape
android:shape="rectangle">
<solid android:color="@color/colorAccent" />/>
<size android:width="5dip" />
<stroke android:color="@color/colorAccent" />
</shape>
</item>
</layer-list>
Creating horizontal and vertical dotted lines in android
I found the solution
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90" >
<shape android:shape="line" >
<stroke
android:dashGap="6px"
android:dashWidth="6px"
android:color="#C7B299" />
</shape>
</rotate>
OR
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:drawable="@drawable/horizontal_line"/>
Drawable xml with horizontal line and circle in middle
Keep it simple
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:height="1dp"
android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="#ff0000" />
</shape>
</item>
<item
android:width="56dp"
android:height="56dp"
android:gravity="center">
<shape android:shape="oval">
<solid android:color="#ff0000" />
</shape>
</item>
</layer-list>
output
Vertical Drawable Line on Left Border of Drawable Rectangle?
This can be achieved with:
- A normal rectangle as the outer white border
- An orange solid rectangle to represent the left line that has
android:gravity="left"
to position it to the left and the paddings adjusted to displace the left line to the right, top, and bottom as you need
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="@color/white" />
<corners android:radius="20dp" />
</shape>
</item>
<item
android:bottom="15dp"
android:gravity="left"
android:left="1dp"
android:top="15dp">
<rotate android:fromDegrees="180">
<shape android:shape="rectangle">
<solid android:color="#FF9800" />
<size android:width="3dp" />
</shape>
</rotate>
</item>
</layer-list>
Previews with different TextView
sizes:
Related Topics
Android Textview:"Do Not Concatenate Text Displayed with Settext"
Android Asynctask Testing with Android Test Framework
Wrong Requestcode in Onactivityresult
How to Open Standard Google Map Application from My Application
How to Programmatically Clear Application Data
Add Views Below Toolbar in Coordinatorlayout
What Do Gc_For_Malloc, Gc_Explicit, and Other Gc_* Mean in Android Logcat
Custom Event Listener on Android App
Application Installation Failed in Android Studio
How to Add Multiple Widgets in the Same App
How to Create an Android Application in Android Studio That Uses the Google Maps API V2
How to Create Tests in Android Studio
Play Sound on Button Click Android
Creating Viewholders for Listviews with Different Item Layouts