将图像居中在LinearLayout的底部和我的应用程序的底部之间

时间:2019-02-20 17:07:21

标签: java android xml layout

我试图将ImageView放在我的LinearLayout底部和App底部之间的屏幕中心,我尝试使用id失败。

这是我要搜索的图像:

enter image description here

所以我想将cookie放在1到2之间


这是我的代码:

<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:background="@drawable/bg"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/cookie"
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:src="@drawable/cookie2"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/layout"

        />

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#6000"
        android:layout_gravity="center_horizontal"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:id="@+id/click"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/cookie_msg"
            android:textColor="@color/whiteColor"
            android:fontFamily="@font/kavoon"
            android:textSize="24sp"
            android:gravity="center"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/kavoon"
            android:gravity="center"
            android:text="@string/cps_msg"
            android:textColor="@color/whiteColor"
            android:textSize="15sp" />

    </LinearLayout>

1 个答案:

答案 0 :(得分:1)

这应该可以解决问题

 <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:background="@drawable/bg"
        tools:context=".MainActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/layout"
            android:gravity="center">

          <!--wrap image view inside this linear layout-->
          <ImageView
            android:id="@+id/cookie"
            android:layout_width="240dp"
            android:layout_height="240dp"
            android:src="@drawable/cookie2"/>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="#6000"
            android:layout_gravity="center_horizontal"
            android:gravity="center_vertical"
            android:orientation="vertical">

            <TextView
                android:id="@+id/click"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/cookie_msg"
                android:textColor="@color/whiteColor"
                android:fontFamily="@font/kavoon"
                android:textSize="24sp"
                android:gravity="center"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/kavoon"
                android:gravity="center"
                android:text="@string/cps_msg"
                android:textColor="@color/whiteColor"
                android:textSize="15sp" />

        </LinearLayout>
</RelativeLayout>