android如何向片段添加高程
我有一个包含android如何向片段添加高程,android,android-fragments,Android,Android Fragments,我有一个包含卡片视图的 而FoodCardFragment通过的FrameLayout food\u card\u视图显示 可以找到显示FoodCardFragment的RandomFragment代码 我试过给出片段或框架布局立面,但在我的手机上,它仍然没有漂浮在随机片段上方 我应该如何添加它 在您的舱单中声明 android:hardwareAccelerated="true" 指向放置片段的活动,并使用cardView上的属性 app:cardElevation="5dp" 在你的舱
卡片视图的
而FoodCardFragment
通过的FrameLayout food\u card\u视图显示
可以找到显示FoodCardFragment
的RandomFragment
代码
我试过给出片段
或框架布局
立面,但在我的手机上,它仍然没有漂浮在随机片段
上方
我应该如何添加它
在您的舱单中声明
android:hardwareAccelerated="true"
指向放置片段的活动,并使用cardView上的属性
app:cardElevation="5dp"
在你的舱单上声明
android:hardwareAccelerated="true"
指向放置片段的活动,并使用cardView上的属性
app:cardElevation="5dp"
添加边距(如果不起作用)将父布局添加为线性
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/food_card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp"
app:cardCornerRadius="5dp"
app:cardElevation="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/food_card"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:elevation="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/food_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
app:srcCompat="@drawable/food_image_place_holder" />
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/food_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:text="Food Name"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/food_card" />
<FrameLayout
android:id="@+id/tags_frame"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/food_name" />
<ImageButton
android:id="@+id/more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="15dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_more_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tags_frame" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
如果边距不起作用,则添加边距将父布局添加为线性
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/food_card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp"
app:cardCornerRadius="5dp"
app:cardElevation="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/food_card"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:elevation="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/food_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
app:srcCompat="@drawable/food_image_place_holder" />
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/food_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:text="Food Name"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/food_card" />
<FrameLayout
android:id="@+id/tags_frame"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/food_name" />
<ImageButton
android:id="@+id/more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="15dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_more_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tags_frame" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我的解决方法是将框架布局
放在CardView
中,而不是使用CardView
作为根的片段,在我的例子中,片段
是FoodCardFragment
这是框架布局
:
<android.support.v7.widget.CardView
android:id="@+id/food_card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="30dp"
app:layout_constraintBottom_toTopOf="@+id/button_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:cardElevation="4dp"
app:cardCornerRadius="5dp">
<FrameLayout
android:id="@+id/food_card_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
这是我的预期结果:
我的解决方法是将框架布局
放在CardView
中,而不是使用CardView
作为根的片段
,在我的例子中,片段
是FoodCardFragment
这是框架布局
:
<android.support.v7.widget.CardView
android:id="@+id/food_card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="30dp"
app:layout_constraintBottom_toTopOf="@+id/button_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:cardElevation="4dp"
app:cardCornerRadius="5dp">
<FrameLayout
android:id="@+id/food_card_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
这是我的预期结果:
在片段食物卡
中的食物卡
视图中添加边距。
添加包装框架布局。在碎片食物卡
中为食物卡视图
添加边距。
添加一个包装框布局。在所有包装框上应用边距4dpside@RajasekaranM在哪一侧?在所有一侧设置版面边距如果不起作用,使用卡片的父版面是任何其他版面在所有一侧应用边距4dpside@RajasekaranM在哪一侧?如果不工作,则在所有一侧设置布局边距,使用卡的父布局是任何其他布局都不起作用。我刚刚在GitHub上查看了您的代码,您的片段在MainActivity上,您是否在mainfest中的MainActivity下包含了hardwareAccelerated=“true”?如果是,请将其安装在模拟器或物理设备上进行测试,XML预览显示不太好我的手机或模拟器没有显示高度。代码已更新。只需更改app:cardElevation=“5dp”而不是android:elevationYou image就不会给我想要的效果。食物的形象是漂浮的。这是意料之中的。如果你仔细看一看,你会发现在食物图像的工具栏下面有一张大卡片。我想要提升它。那没用。我刚刚在GitHub上浏览了你的代码,你的片段在MainActivity上,你是否在mainfest的MainActivity下包含了硬件acelerated=“true”?如果是,请将其安装在模拟器或物理设备上进行测试,XML预览显示不太好我的手机或模拟器没有显示高度。代码已更新。只需更改app:cardElevation=“5dp”而不是android:elevationYou image就不会给我想要的效果。食物的形象是漂浮的。这是意料之中的。如果你仔细看一看,你会发现在食物图像的工具栏下面有一张大卡片。我想要它的高度。添加边距有效,但是由该高度创建的阴影非常不自然。您必须添加比您的高度更多的边距,因此将边距添加为10dp或将高度减少为4dp。边距有效,但是由该高度创建的阴影非常不自然。您必须添加比您的高度更多的边距,因此将边距添加为10dp或将标高降低为4dp