我创建了一个使用CardView.
的android布局,但是,我还创建了一个TextView
,它应该放在CardViews.
的顶部。但是,我注意到TextView
重叠在其中一张卡上,所以我去了并更改了XML中卡的位置(包含在相对布局中)。但是,我再次运行它,没有任何改变。如果您能向我展示如何纠正错误,我们将不胜感激。
XML代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_welcome_page"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/redbck"
android:layout_height="match_parent"
tools:context="com.avinashdavid.trivialtrivia.UI.ActivityWelcomePage"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_below="@+id/toolbar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_start_game"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
android:layout_marginBottom="@dimen/activity_vertical_margin"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer1"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<ImageView
android:id="@+id/imageview_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
</RelativeLayout>
<LinearLayout
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="@+id/startgame"
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_game"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/start_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_statistics"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
android:layout_marginBottom="@dimen/activity_vertical_margin"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer2"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<ImageView
android:id="@+id/imageview_statistics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
</RelativeLayout>
<LinearLayout
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Online Mode"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/statistics_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_statistics2"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
android:layout_marginBottom="@dimen/activity_vertical_margin"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer22"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<ImageView
android:id="@+id/imageview_statistics2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
</RelativeLayout>
<LinearLayout
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer22"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Online Mode"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/statistics_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_instructions"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
android:layout_marginBottom="@dimen/activity_vertical_margin"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer3"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<ImageView
android:id="@+id/imageview_instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"/>
</RelativeLayout>
<LinearLayout
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report a Bug"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/instructions_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_acknowledgments"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/imageview_acknowledgments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer4"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Terms and Conditions"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/acknowledgements_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Select a Game Mode"
android:textColor="#fff"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
答案 0 :(得分:1)
您只需将主要的RelativeLayout
替换为LinearLayout
和
将TextView
放在顶部。看看下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_welcome_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbck"
android:orientation="vertical"
tools:context="com.avinashdavid.trivialtrivia.UI.ActivityWelcomePage">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Select a Game Mode"
android:textSize="30sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_start_game"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/imageview_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/startgame"
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_game"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/start_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_acknowledgments"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_weight="1"
card_view:cardCornerRadius="2dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00d4ff">
<RelativeLayout
android:id="@+id/imagecontainer4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/imageview_acknowledgments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imagecontainer4"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
style="@style/WelcomeHeadings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Terms and Conditions"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
style="@style/StatsContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:text="@string/acknowledgements_subtitle"
android:textColor="#fff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>