How to create a Dashed / Dotted line in Android XML
In this post, We create a Dashed line in Android XML to differentiate two layouts.
Suppose, we create two TextViews in our XML layout and we want to differentiate that layout with a line, for that, we create a dashed line and add between that two TextViews.
Firstly, open the Android Studio and create a new project and right-click on the drawable directory and click on a new drawable resource file.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#C7B299"
android:dashWidth="10px"
android:dashGap="10px"
android:width="1dp"/>
</shape>
Then use that drawable resource file between text views as an image view in your XML.
activity_main.xml
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:src="@drawable/dotted"
android:layerType="software"/>
</LinearLayout>
Then run your app and your dashed line is shown between the layouts.
Subscribe to Harpreet studio on Youtube
Like Harpreet Studio on Facebook
Follow me on Instagram
Thanks a lot!
ReplyDeleteUnlike paid advertising, which requires an ongoing budget, SEO hamping is a long-term investment that yields better results over time. By applying SEO techniques such as content optimization, link structure, and using the right keywords, you can improve your website's ranking and, as a result, increase your sales and income.
ReplyDelete