我正在尝试构建一个基于CardView的布局,该布局同时包含MapFragment和ConstraintLayout。问题是cardview的边缘是圆形的,但这并没有应用到Card内部的MapFragment和ConstraintView。
我已尝试使用here中所述的带有圆角的Drawables,但是它似乎不起作用,并且Card的圆角要么被尖锐的边缘覆盖,要么留下了边框(取决于我是否使用可绘制或忽略它)。
我在做什么错了,还是想念?
布局XML如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="wrap_content"
android:layout_margin="8dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="20dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/view_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintGuide_end="167dp"
app:layout_constraintStart_toStartOf="parent" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:cameraZoom="13"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:liteMode="true"
app:mapType="normal" />
<android.support.constraint.ConstraintLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@drawable/drawable_rounded_right"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/map"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/view_foreground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/drawable_rounded_right_upper"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_conversion_absoluteHeight="105dp"
tools:layout_conversion_absoluteWidth="162dp"
tools:layout_editor_absoluteY="5dp">
<TextView
android:id="@+id/txtFname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="30dp"
tools:layout_conversion_absoluteWidth="59dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hours"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="@+id/txtHours"
app:layout_constraintStart_toStartOf="@+id/txtHours"
app:layout_constraintTop_toBottomOf="@+id/txtHours"
tools:layout_conversion_absoluteHeight="19dp"
tools:layout_conversion_absoluteWidth="38dp"
tools:layout_editor_absoluteX="293dp"
tools:layout_editor_absoluteY="80dp" />
<TextView
android:id="@+id/txtHours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="10"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="46dp"
tools:layout_conversion_absoluteWidth="38dp" />
<TextView
android:id="@+id/txtGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
app:layout_constraintStart_toStartOf="@+id/txtFname"
app:layout_constraintTop_toBottomOf="@+id/txtFname"
tools:layout_conversion_absoluteHeight="19dp"
tools:layout_conversion_absoluteWidth="31dp"
tools:layout_editor_absoluteX="185dp"
tools:layout_editor_absoluteY="64dp" />
<TextView
android:id="@+id/textView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/txtGender"
app:layout_constraintTop_toBottomOf="@+id/txtGender"
tools:layout_conversion_absoluteHeight="19dp"
tools:layout_conversion_absoluteWidth="24dp"
tools:layout_editor_absoluteX="185dp"
tools:layout_editor_absoluteY="83dp" />
<TextView
android:id="@+id/txtAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
app:layout_constraintBaseline_toBaselineOf="@+id/textView24"
app:layout_constraintStart_toEndOf="@+id/textView24"
tools:layout_conversion_absoluteHeight="19dp"
tools:layout_conversion_absoluteWidth="8dp"
tools:layout_editor_absoluteX="217dp"
tools:layout_editor_absoluteY="83dp" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/btnAction1"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/drawable_rounded_right_lower"
android:text="Action"
android:textColor="@color/brightblue"
android:textColorLink="@color/brightblue"
android:textSize="12dp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_foreground"
tools:layout_conversion_absoluteHeight="30dp"
tools:layout_conversion_absoluteWidth="88dp" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
答案 0 :(得分:0)
将地图视图包含在卡片视图中并更改卡片视图的半径可能是不错的选择。
<android.support.v7.widget.CardView
android:layout_width="300dp"
android:layout_height="350dp"
app:cardCornerRadius="12dp">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cameraZoom="13"
app:liteMode="true"
app:mapType="normal" />
</android.support.v7.widget.CardView>
我真的认为您的视图层次结构相当嵌套,总计为redundancy ...(很好地使用一个Constraint layout可以产生相同的接口,您大约有3个)。我想您必须对此进行努力。
此外,您可以向地图添加一些边距...,将其从边缘移开。 (我希望这是您想要实现的目标)