android中如何在相对布局内设置Linearlayout Center //xml https://pasteboard.co/
这是我的Xml和当前屏幕,您可以看到位于Linearlayout内部的imageview未设置为中心。我已经把重心放在直线布局上了,但它没有设置中心。我不知道我犯了什么错误,甚至在工具栏上。我也试着在下面设置阴影,但它没有出现。有人能告诉我我做错了什么吗。 [![在此处输入图像描述][1][1]android中如何在相对布局内设置Linearlayout Center //xml https://pasteboard.co/,android,Android,这是我的Xml和当前屏幕,您可以看到位于Linearlayout内部的imageview未设置为中心。我已经把重心放在直线布局上了,但它没有设置中心。我不知道我犯了什么错误,甚至在工具栏上。我也试着在下面设置阴影,但它没有出现。有人能告诉我我做错了什么吗。 [![在此处输入图像描述][1][1] 这是我当前屏幕中的预期屏幕,使用当前xml,我无法设置进入线性布局的Imageview不在中心,阴影下方的工具栏也不在中心。请建议我如何保持其中心,以及如何将阴影放置在工具栏下方的预期屏幕上。尝试此操作
这是我当前屏幕中的预期屏幕,使用当前xml,我无法设置进入线性布局的Imageview不在中心,阴影下方的工具栏也不在中心。请建议我如何保持其中心,以及如何将阴影放置在工具栏下方的预期屏幕上。尝试此操作使您的
LinearLayout
android:layout\u centerInParent=“true”
如下代码
<RelativeLayout
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header"
android:fillViewport="true"
android:paddingLeft="80dp"
android:paddingRight="80dp"
android:paddingTop="40dp">
<LinearLayout
android:id="@+id/appLogogImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circular_textview_drawable"
android:gravity="center">
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="center"
android:background="@drawable/ic_share_illustration" />
</LinearLayout>
<TextView
android:id="@+id/appTextview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appLogogImageView"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:letterSpacing="-0.03"
android:paddingTop="@dimen/baseline_grid_4x"
android:text="Sharing is Caring"
android:textColor="@color/colorDusk"
android:textSize="20.1sp"
android:textStyle="normal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/appTextview"
android:fontFamily="sans-serif"
android:gravity="center_horizontal"
android:letterSpacing="-0.03"
android:lineSpacingExtra="6sp"
android:text="Share ContSync with your friends to get them onboard"
android:textColor="@color/colorBlueyGrey"
android:textSize="14sp"
android:textStyle="normal" />
</RelativeLayout>
</RelativeLayout>
// toolbar .xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:elevation="@dimen/app_bar_default_elevation"
style="@style/TextAppearance.Widget.Event.Toolbar.Title"
tools:title="@string/label_select_your_country" />
</android.support.design.widget.AppBarLayout>
https://pasteboard.co/
编辑
<LinearLayout
android:id="@+id/appLogogImageView"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:background="@drawable/circular_textview_drawable"
android:gravity="center">
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="center"
android:background="@drawable/ic_share_illustration" />
</LinearLayout>
输出
<LinearLayout
android:id="@+id/appLogogImageView"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:background="@drawable/circular_textview_drawable"
android:gravity="center">
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_gravity="center"
android:background="@drawable/ic_share_illustration" />
</LinearLayout>
在
线性布局中
添加这一行android:layout\u centerInParent=“true”
以使其位于RelativeLayout的父级的中心below@MakleeLee分享你的全部布局代码,在我的device@MakleeLee删除android:layout_下方=“@+id/header”
从线性布局的相对布局父级在我的屏幕中,它的中心即将出现,但它将下降。它不是预期的尖叫。我必须保持图像顶部填充40 dp,但它即将出现center@MakleeLee删除android:paddingTop=“40dp”
从您的相对位置,我做了同样的事情,但它的线性布局发生了变化down@MakleeLee你的代码对我来说很好。它在我的布局中看起来是居中的。但是看,我预期的屏幕图像是从顶部开始的,分辨率为40 dp。你想让布局正好在右中央吗?。我认为下面的答案就是这样做。不是吗?