android开发之居中向上移动xxdp显示

来源:互联网 发布:深圳壹叁叁网络老挝 编辑:程序博客网 时间:2024/05/01 10:22

这些都是作者,在开发过程中,一时没有想起来的解决思路,最后经过同事提示才完成的一些个人经验积累!
如何让控件居中且向上xxdp显示,如图1-1:
居中且向上xxdp显示

<?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:background="@color/color_fff"                android:orientation="vertical"                android:gravity="center">    <ImageView            android:id="@+id/iv_offline_cache"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/hs"            android:layout_gravity="center"            />    <TextView            android:id="@+id/tv_offline_cache"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="@string/text_offline_cache"            android:textColor="@color/color_666"            android:textSize="@dimen/s_16dp"            android:layout_gravity="center"            android:layout_marginTop="@dimen/s_30dp"            android:layout_marginBottom="@dimen/s_11dp"            /></LinearLayout>

基本思路是这样的:
首先: 父布局为LinearLayout
然后: 在父布局中进行居中显示:android:gravity=”center”
接下来: 在每个子控件中:android:layout_gravity=”center”
最后: 在最底部子控件中:android:layout_marginBottom=”@dimen/s_xxdp”

0 0
原创粉丝点击