添加TextView的布局? [英] Add textview to layout?
问题描述
我不能把我上面的按钮,一个TextView,而无需我的按钮移动......我怎样才能解决这个问题?
一直停留在这4个小时......因为我想在我的布局添加一个TextView这是悲伤...
我在中心4个按钮的布局。我只是想添加上述四个按钮一个TextView,喜欢这里所示(TextView的应该是红色的地方):
当我把上面的按钮的TextView在XML布局视图中的拖放将无法工作。它只是DIS中心的按钮。我也试着做什么<一个href=\"http://stackoverflow.com/questions/7887815/android-how-do-i-position-views-in-an-offset-relative-to-the-center-top-bottom\">this回答表明,但随后的锚视图本身不会被定位在中心!
下面是我的XML:
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=com.example.me.circleswithmap.MainActivity
机器人:ID =@ + ID /布局
机器人:比重=中心&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /蓝
机器人:layout_alignParentTop =真
机器人:layout_alignParentLeft =真
机器人:layout_alignParentStart =真
机器人:背景=@绘制/ bluesquare/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /绿
机器人:layout_below =@ + ID /蓝
机器人:layout_alignLeft =@ + ID /蓝
机器人:layout_alignStart =@ + ID /蓝
机器人:背景=@绘制/ greensquare/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /红
机器人:layout_alignTop =@ + ID /蓝
机器人:layout_toRightOf =@ + ID /蓝
机器人:layout_toEndOf =@ + ID /蓝
机器人:背景=@绘制/ redsquare/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /紫色
机器人:layout_alignBottom =@ + ID /绿
机器人:layout_alignLeft =@ + ID /红
机器人:layout_alignStart =@ + ID /红
机器人:背景=@绘制/ purplesquare/&GT; 需要一些TextView中也!每当我添加一个,IT DISCENTERS按钮的休息!
&LT; / RelativeLayout的&GT;
我应该怎么做才能解决这个问题?为什么这么难?我不应该用相对布局?我怎样才能被相互停止?
太感谢了,
NullPointerException异常
&LT;的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=com.example.ruchir.circleswithmap.MainActivity
机器人:ID =@ + ID /布局&GT; &LT;的LinearLayout的android:layout_width =WRAP_CONTENT
机器人:ID =@ + ID / TEXT_CONTAINER
机器人:layout_centerInParent =真
机器人:layout_alignParentTop =真
机器人:layout_height =WRAP_CONTENT&GT;
&LT;的TextView的android:layout_width =match_parent
机器人:文字=pruebaskjahlkdjahslk
机器人:layout_height =match_parent/&GT;
&LT; / LinearLayout中&GT; &LT; RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_centerInParent =真
机器人:layout_height =WRAP_CONTENT&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /蓝
机器人:layout_alignParentLeft =真
机器人:layout_alignParentStart =真/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /绿
机器人:layout_below =@ + ID /蓝
机器人:layout_alignLeft =@ + ID /蓝
机器人:layout_alignStart =@ + ID /蓝/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /红
机器人:layout_alignTop =@ + ID /蓝
机器人:layout_toRightOf =@ + ID /蓝
机器人:layout_toEndOf =@ + ID /蓝/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /紫色
机器人:layout_alignBottom =@ + ID /绿
机器人:layout_alignLeft =@ + ID /红
机器人:layout_alignStart =@ + ID /红/&GT; &LT; / RelativeLayout的&GT;
&LT; / RelativeLayout的&GT;
横向方向
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=com.example.me.circleswithmap.MainActivity
机器人:ID =@ + ID /布局&GT; &LT;的LinearLayout的android:layout_width =WRAP_CONTENT
机器人:ID =@ + ID / TEXT_CONTAINER
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真正的&GT;
&LT;的TextView
机器人:layout_width =match_parent
机器人:文字=20:00
机器人:layout_height =match_parent
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
/&GT;
&LT; / LinearLayout中&GT; &LT; RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / RelativeLayout的
机器人:layout_below =@ ID / TEXT_CONTAINER
机器人:layout_centerVertical =真
机器人:layout_centerHorizontal =真
&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /蓝
机器人:layout_alignParentTop =真
机器人:layout_alignParentLeft =真
机器人:layout_alignParentStart =真/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /绿
机器人:layout_below =@ + ID /蓝
机器人:layout_alignLeft =@ + ID /蓝
机器人:layout_alignStart =@ + ID /蓝/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /红
机器人:layout_alignTop =@ + ID /蓝
机器人:layout_toRightOf =@ + ID /蓝
机器人:layout_toEndOf =@ + ID /蓝/&GT; &LT;的ImageButton
机器人:layout_width =100dp
机器人:layout_height =100dp
机器人:ID =@ + ID /紫色
机器人:layout_alignBottom =@ + ID /绿
机器人:layout_alignLeft =@ + ID /红
机器人:layout_alignStart =@ + ID /红/&GT; &LT; / RelativeLayout的&GT;&LT; / RelativeLayout的&GT;
I cant put a textview above my buttons without having my buttons move...How can I fix this?
Been stuck on this for 4 hours...Which is sad because I'm trying to add a textview on my layout...
I have a layout with 4 buttons in the center. I simply want to add a textview above the four buttons, like illustrated here (TextView should be in the place of the red) :
The drag and drop in the XML layout view will not work when I place the textview above the buttons. It just dis centers the buttons. I also tried doing what this answer suggested, but then the anchor view itself would not be positioned in the center!
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.me.circleswithmap.MainActivity"
android:id="@+id/layout"
android:gravity="center">
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Blue"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/bluesquare" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Green"
android:layout_below="@+id/Blue"
android:layout_alignLeft="@+id/Blue"
android:layout_alignStart="@+id/Blue"
android:background="@drawable/greensquare" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Red"
android:layout_alignTop="@+id/Blue"
android:layout_toRightOf="@+id/Blue"
android:layout_toEndOf="@+id/Blue"
android:background="@drawable/redsquare" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"
android:background="@drawable/purplesquare" />
NEED SOME TEXTVIEW ALSO! WHENEVER I ADD ONE, IT DISCENTERS THE REST OF THE BUTTONS!
</RelativeLayout>
What should I do to tackle this problem? Why is it so difficult? Should I not use Relative Layout? How can I stop this from being relative to each other?
Thanks so much,
NullPointerException
<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"
tools:context="com.example.ruchir.circleswithmap.MainActivity"
android:id="@+id/layout">
<LinearLayout android:layout_width="wrap_content"
android:id="@+id/text_container"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_height="wrap_content">
<TextView android:layout_width="match_parent"
android:text="pruebaskjahlkdjahslk"
android:layout_height="match_parent"/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Blue"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Green"
android:layout_below="@+id/Blue"
android:layout_alignLeft="@+id/Blue"
android:layout_alignStart="@+id/Blue"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Red"
android:layout_alignTop="@+id/Blue"
android:layout_toRightOf="@+id/Blue"
android:layout_toEndOf="@+id/Blue"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"/>
</RelativeLayout>
</RelativeLayout>
Landscape orientation
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.me.circleswithmap.MainActivity"
android:id="@+id/layout">
<LinearLayout android:layout_width="wrap_content"
android:id="@+id/text_container"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="match_parent"
android:text="20:00"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout"
android:layout_below="@id/text_container"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Blue"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Green"
android:layout_below="@+id/Blue"
android:layout_alignLeft="@+id/Blue"
android:layout_alignStart="@+id/Blue"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Red"
android:layout_alignTop="@+id/Blue"
android:layout_toRightOf="@+id/Blue"
android:layout_toEndOf="@+id/Blue"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"/>
</RelativeLayout>
</RelativeLayout>
这篇关于添加TextView的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!