[英]Android textview is not showing up in relative layout.
我在使用android相對布局時遇到了一些麻煩。 我希望文本視圖“ Maze”出現在兩個按鈕的中央:退出並播放。 但是,該文本沒有出現。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ui.AMazeActivity" >
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#333333"
android:layout_alignBottom="@+id/play"
android:layout_alignParentTop="true"/>
<Button
android:id="@+id/quit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="@string/quit_button_text"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:text="@string/play_button_text"
android:textColor="@android:color/white"/>
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_toStartOf="@+id/quit"
android:layout_toEndOf="@+id/play"
android:layout_alignBottom="@+id/quit"
android:layout_alignTop="@+id/quit"
android:text="@string/maze_textview_text"
android:textColor="@android:color/white"/>
</RelativeLayout>
這是圖片:(請注意,迷宮文字應出現在退出和游戲之間)
嘗試這個:
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_toStartOf="@+id/play"
android:layout_toEndOf="@+id/quit"
android:layout_alignBottom="@+id/quit"
android:layout_alignTop="@+id/quit"
android:text="@string/maze_textview_text"
android:textColor="@android:color/white"/>
用這個。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ui.AMazeActivity" >
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/play"
android:layout_alignParentTop="true"
android:background="#333333" />
<Button
android:id="@+id/quit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="quit"
android:textColor="@android:color/white" />
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:text="play"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/play"
android:layout_alignBottom="@+id/play"
android:layout_centerHorizontal="true"
android:text="Maze"
android:textColor="#fff"
android:textSize="17sp" />
</RelativeLayout>
僅對於此小部件,應該使用LinearLayout並將其方向設置為Horizontal。
我將為您入門而編寫一些代碼,但是我真的不想花我的時間編寫應有的一切。無論如何,我敢肯定,您會馬上發現它的。
<LinearLayout
android:orientation="horizontal">
<!-- And whatever other stuff you have to set,like width ,height,bla bla -->
<Button></Button> <!-- This is the Quit button-->
<TextView></TextView> <!-- This is the TextView that shows "Maze"-->
<Button></Button> <!-- This is the Play button-->
</LinearLayout>
因此,總而言之,通過將LinearLayout與水平方向一起使用,您在布局中添加的每個元素都將被放置在之前添加的元素的右側。第一個元素,get被添加在布局的左上角。
如果您需要更多信息,請通過評論告知我,我們將為您提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.