Я новичок в Android. Я хочу это сделать.
но я не знаю, как это сделать ... Моя это
Я хочу перекрыть шину (ImageView
) на линии (View
).
А это мой код ...
activity_main.xml
<?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:layout_margin = "30dp"
android:orientation = "vertical"
tools:context = ".MainActivity">
<android.support.design.widget.TabLayout
android:id = "@+id/tabLayout"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"/>
<android.support.v4.view.ViewPager
android:id = "@+id/viewPager"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_below = "@+id/tabLayout"/>
<ImageView
android:id = "@+id/busImage"
android:layout_width = "50dp"
android:layout_height = "50dp"
android:layout_below = "@+id/tabLayout"
android:src = "@drawable/ic_directions_bus_24dp"/>
</RelativeLayout>
activity_custom.xml
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:orientation = "horizontal"
android:weightSum = "8">
<RelativeLayout
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:layout_weight = "2">
<View
android:id = "@+id/line1"
android:layout_width = "5dp"
android:layout_height = "wrap_content"
android:layout_centerInParent = "true"
android:layout_weight = "1"
android:background = "@color/colorDS"/>
<View
android:id = "@+id/line2"
android:layout_width = "5dp"
android:layout_height = "wrap_content"
android:layout_centerInParent = "true"
android:layout_weight = "1"
android:background = "@color/colorDS"/>
</RelativeLayout>
<View
android:id = "@+id/view"
android:layout_width = "0dp"
android:layout_height = "match_parent" />
<RelativeLayout
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:layout_margin = "10dp"
android:layout_weight = "6">
<TextView
android:id = "@+id/stNm"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textSize = "20dp"/>
<TextView
android:id = "@+id/arsId"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/stNm"
android:textSize = "13dp"/>
</RelativeLayout>
</LinearLayout>
Вы можете использовать FrameLayout
Вы можете добиться этого макета с помощью RecyclerView. вам нужно поместить изображение шины в каждый элемент RecyclerView и соответствующим образом обработать видимость.
Вот макет элемента для RecyclerView.
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "100dp"
xmlns:app = "http://schemas.android.com/apk/res-auto">
<View
android:id = "@+id/line1"
android:layout_width = "5dp"
android:layout_height = "match_parent"
app:layout_constraintStart_toStartOf = "parent"
android:background = "#ff0000"
android:layout_marginStart = "32dp"/>
<TextView
android:id = "@+id/stNm"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
app:layout_constraintStart_toEndOf = "@id/line1"
android:layout_marginStart = "40dp"
android:text = "testzczczc"
android:textSize = "20dp"/>
<TextView
android:id = "@+id/arsId"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
app:layout_constraintStart_toEndOf = "@id/line1"
app:layout_constraintTop_toBottomOf = "@id/stNm"
android:layout_marginStart = "40dp"
android:text = "tesdfsfsfsst"
android:textSize = "20dp"/>
<ImageView
android:id = "@+id/busImage"
android:layout_width = "40dp"
android:layout_height = "40dp"
android:src = "@drawable/bus"
app:layout_constraintTop_toTopOf = "parent"
app:layout_constraintStart_toStartOf = "@id/line1"
app:layout_constraintEnd_toEndOf = "@id/line1"/>
</android.support.constraint.ConstraintLayout>
здесь вам нужно обработать видимость busImage.
вы используете ресайклер или список с макетом элемента, указанным выше. Если да, вы должны поместить изображение своего автобуса в каждый элемент и соответствующим образом обработать видимость.