旁边的添加按钮TextView的? [英] Add TextView next to buttons?
问题描述
我在中心4个按钮的布局。我只是要新增一个TextView四个按键(不移动的四个按键从中心),喜欢这里所示(TextView的应该是红色的地方):
[![此处输入的形象描述] [1] [1]
现在,我有自己的线性布局的TextView并在自己的相对布局的四个按键,都在一个大的相对布局。当我曾经尝试移动的TextView到按钮的左侧,按键移到右边。我该如何实现我说明什么呢?这里是我的XML:
<?XML版本=1.0编码=UTF-8&GT?;
<的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.ruchir.circleswithmap.MainActivity
机器人:ID =@ + ID /布局
机器人:比重=中心
机器人:背景=#010101> <的LinearLayout
机器人:ID =@ + ID / TEXT_CONTAINER
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_above =@ + ID / RelativeLayout的
机器人:layout_centerHorizontal =真
机器人:layout_marginBottom =10dp
>
<的TextView 机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:文字=20:00
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
机器人:TEXTSIZE =50SP
机器人:文字颜色=#fbfafa 机器人:ID =@ + ID / timetext/>
< / LinearLayout中> < RelativeLayout的
机器人:ID =@ + ID / RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真正的> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /蓝
机器人:layout_alignParentTop =真
机器人:layout_alignParentLeft =真
机器人:layout_alignParentStart =真
机器人:背景=@绘制/ bluesquare/> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /绿
机器人:layout_below =@ + ID /蓝
机器人:layout_alignLeft =@ + ID /蓝
机器人:layout_alignStart =@ + ID /蓝
机器人:背景=@绘制/ greensquare/> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /红
机器人:layout_alignTop =@ + ID /蓝
机器人:layout_toRightOf =@ + ID /蓝
机器人:layout_toEndOf =@ + ID /蓝
机器人:背景=@绘制/ redsquare/> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /紫色
机器人:layout_alignBottom =@ + ID /绿
机器人:layout_alignLeft =@ + ID /红
机器人:layout_alignStart =@ + ID /红
机器人:背景=@绘制/ purplesquare/>< / RelativeLayout的> < / RelativeLayout的>
把TextView的一个的LinearLayout而在另一个的LinearLayout四个按钮,然后试图水平的权重,以单行排列,然后可能工作了。
code可能是如下:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的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.ruchir.circleswithmap.MainActivity
机器人:ID =@ + ID /布局
机器人:比重=中心
机器人:背景=#010101
机器人:weightSum =100> <的LinearLayout
机器人:ID =@ + ID / TEXT_CONTAINER
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_above =@ + ID / RelativeLayout的
机器人:layout_centerHorizontal =真
机器人:layout_marginBottom =10dp
机器人:layout_weight =50
>
<的TextView 机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:文字=20:00
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
机器人:TEXTSIZE =50SP
机器人:文字颜色=#fbfafa 机器人:ID =@ + ID / timetext/>
< / LinearLayout中> < RelativeLayout的
机器人:ID =@ + ID / RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真
机器人:layout_weight =50> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /蓝
机器人:layout_alignParentTop =真
机器人:layout_alignParentLeft =真
机器人:layout_alignParentStart =真
/> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /绿
机器人:layout_below =@ + ID /蓝
机器人:layout_alignLeft =@ + ID /蓝
机器人:layout_alignStart =@ + ID /蓝
/> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /红
机器人:layout_alignTop =@ + ID /蓝
机器人:layout_toRightOf =@ + ID /蓝
机器人:layout_toEndOf =@ + ID /蓝
/> <的ImageButton
机器人:layout_width =150dp
机器人:layout_height =150dp
机器人:ID =@ + ID /紫色
机器人:layout_alignBottom =@ + ID /绿
机器人:layout_alignLeft =@ + ID /红
机器人:layout_alignStart =@ + ID /红
/> < / RelativeLayout的>< / LinearLayout中>
I have a layout with 4 buttons in the center. I simply want to add a textview next to the four buttons (WITHOUT MOVING THE FOUR BUTTONS FROM THE CENTER), like illustrated here (TextView should be in the place of the red) :
[![enter image description here][1]][1]
Right now, I have the textview in its own linear layout and the four buttons in their own Relative Layout, all in one big relative layout. When ever I try to move the textview to the left of the buttons, the buttons move over to the right. How do I achieve what I illustrated? 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.ruchir.circleswithmap.MainActivity"
android:id="@+id/layout"
android:gravity="center"
android:background="#010101">
<LinearLayout
android:id="@+id/text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="20:00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="50sp"
android:textColor="#fbfafa"
android:id="@+id/timetext" />
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/Blue"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/bluesquare" />
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
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="150dp"
android:layout_height="150dp"
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="150dp"
android:layout_height="150dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"
android:background="@drawable/purplesquare" />
</RelativeLayout>
</RelativeLayout>
Put the textView in one Linearlayout and the four buttons in another LinearLayout and then trying Horizontal weights to align then in a single line might work out.
Code could be as follows
<?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: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.ruchir.circleswithmap.MainActivity"
android:id="@+id/layout"
android:gravity="center"
android:background="#010101"
android:weightSum="100">
<LinearLayout
android:id="@+id/text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_weight = "50"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="20:00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="50sp"
android:textColor="#fbfafa"
android:id="@+id/timetext" />
</LinearLayout>
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="50">
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/Blue"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/Green"
android:layout_below="@+id/Blue"
android:layout_alignLeft="@+id/Blue"
android:layout_alignStart="@+id/Blue"
/>
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/Red"
android:layout_alignTop="@+id/Blue"
android:layout_toRightOf="@+id/Blue"
android:layout_toEndOf="@+id/Blue"
/>
<ImageButton
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"
/>
</RelativeLayout>
</LinearLayout>
这篇关于旁边的添加按钮TextView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!