在视图后面的背景中添加标尺类型元素
问题描述:
在我的XML
中,我有4个视图,三个CardView
和一个只是相对视图(通过活动与其他CardView
一样被夸大,在下面的XML中ID为container
) .我想在每个视图的背景下面附加与每个视图相连的杆类型的元素.
In my XML
I have 4 views, three CardView
s and one is just a relative view (which is inflated as of other CardView
s through activity and it have id of container
in XML below). I want to attach the rod type of element connected with each view one after another in their below in background.
这是我想要的杆元素的代码.
This is code of that rod element I want.
<!-- vertical rod, I want like this rod in background of these four views -->
<RelativeLayout
android:layout_width="4dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="35dp"
android:background="@color/black"/>
这是布局.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ECEAEA"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true"
android:layoutDirection="ltr"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp">
<ScrollView
android:id="@+id/scroll_view_post_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout_head"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view_category_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="12"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/video_detail_category_thumb"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:src="@drawable/logo"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="10"
android:orientation="vertical">
<TextView
android:id="@+id/video_detail_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/video_detail_category_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="15sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<!-- this is the native ad contaainer, I will inflate this in activity -->
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<android.support.v7.widget.CardView
android:id="@+id/relative_layout_content2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear_layout_head"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="12"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/video_detail_category_thumb3"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:src="@drawable/logo"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="10"
android:orientation="vertical">
<TextView
android:id="@+id/video_detail_title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/video_detail_category_title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="15sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_below="@id/linear_layout_head"
android:id="@+id/relative_layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="12"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/video_detail_category_thumb2"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:src="@drawable/logo"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="10"
android:orientation="vertical">
<TextView
android:id="@+id/video_detail_title3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/video_detail_category_title3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="15sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
我想要那些杆型元素作为背景图片.预先谢谢你.
I want those rod type of element as of the picture in the background. thank you in advance.
答
尝试一下,您的项目是否具有ConstraintLayout?
Try this, is your project has ConstraintLayout?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ECEAEA"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true"
android:layoutDirection="ltr"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
>
<ScrollView
android:id="@+id/scroll_view_post_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="4dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentBottom="true"
android:layout_marginLeft="35dp"
app:layout_constraintLeft_toLeftOf="parent"
android:background="@color/black"/>
<LinearLayout
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/linear_layout_head"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view_category_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="12"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/video_detail_category_thumb"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:src="@drawable/logo"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="10"
android:orientation="vertical">
<TextView
android:id="@+id/video_detail_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/video_detail_category_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="15sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
<!-- this is the native ad contaainer, I will inflate this in activity -->
<RelativeLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<android.support.v7.widget.CardView
android:id="@+id/relative_layout_content2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear_layout_head"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="12"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/video_detail_category_thumb3"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:src="@drawable/logo"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="10"
android:orientation="vertical">
<TextView
android:id="@+id/video_detail_title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/video_detail_category_title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="15sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
app:layout_constraintTop_toBottomOf="@id/linear_layout_head"
android:id="@+id/relative_layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="12"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/video_detail_category_thumb2"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_weight="2"
android:src="@drawable/logo"
app:civ_border_color="@color/white"
app:civ_border_width="2dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="10"
android:orientation="vertical">
<TextView
android:id="@+id/video_detail_title3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/video_detail_category_title3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/app_name"
android:textColor="@color/color_black"
android:textSize="15sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</RelativeLayout>