我在XML中遇到了TextView问题。 这是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context=".frontScreen">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/plan"
android:shadowColor="@color/colorPrimary"
android:textColor="@color/colorPrimary"
android:textSize="30sp"
android:shadowRadius="2"
android:gravity="center_horizontal"
android:shadowDx="1"
android:shadowDy="1"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorAccent"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/activity_horizontal_margin">
<Button
android:id="@+id/plan1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/plan2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ButtonStyle" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
如果我写TextView是线性布局。然后它与按钮重叠。所以我使用2个布局相对和线性。 当我在设计中单击TextView时,看起来TextView具有我想要的确切空间但Text消失了
答案 0 :(得分:1)
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context=".frontScreen">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorAccent"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/activity_horizontal_margin">
<Button
android:id="@+id/plan1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/plan2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ButtonStyle" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="plan"
android:shadowColor="@color/colorPrimary"
android:textColor="@color/colorPrimary"
android:textSize="30sp"
android:shadowRadius="2"
android:gravity="center_horizontal"
android:shadowDx="1"
android:shadowDy="1"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
希望这会有所帮助。但为了更好地工作,您需要在单一布局中采用relativelayout和linearlayout。随便问一下这是否有效
编辑:
如果您需要在单个视图中使用此功能,可以尝试
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
android:orientation="horizontal"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="plan"
android:shadowColor="@color/colorPrimary"
android:textColor="@color/colorPrimary"
android:textSize="30sp"
android:shadowRadius="2"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:shadowDx="1"
android:shadowDy="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:gravity="center"
android:orientation="horizontal"
android:layout_centerInParent="true"
android:padding="@dimen/activity_horizontal_margin">
<Button
android:id="@+id/plan1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/plan2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="ButtonStyle" />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>