Android XML布局设计和代码不匹配
我的xml布局设计并不是我的代码所期望的那样。我不会动态地改变任何事情 代码:Android XML布局设计和代码不匹配,android,xml,Android,Xml,我的xml布局设计并不是我的代码所期望的那样。我不会动态地改变任何事情 代码: 看看“abc”,它应该在“5”以下,而不是在中间。 我已经在下面设置了android:layout_=“@+id/rollnoT” 但它仍然显示在中间 请帮我解决这个问题。试试这个 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/and
看看“abc”,它应该在“5”以下,而不是在中间。
我已经在下面设置了android:layout_=“@+id/rollnoT”
但它仍然显示在中间
请帮我解决这个问题。试试这个
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="@+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="@+id/cmtT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="@android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
试试这个吹奏片段
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp" />
<TextView
android:id="@+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rollnoT"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="@+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="@android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
如果您能练习
线性布局
,那就太好了。它解决了很多问题。如果您使用的是RelativeLayout
,那么它在其他视图上是可靠的 你为什么不使用线性布局?我怎么能使用线性布局!我在后台有一个文本视图。查看我的回复帖子
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp" />
<TextView
android:id="@+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rollnoT"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="@+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="@android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>