当前位置: 代码迷 >> Android >> 请教关于界面的显示有关问题
  详细解决方案

请教关于界面的显示有关问题

热度:79   发布时间:2016-04-28 02:14:11.0
请问关于界面的显示问题
请问 如下图显示,  怎么把“新手机号”这个textview 至于该行的中间, 以及怎么把 “新手机”旁边的 edittext对齐 且它们都处于该行的中间?
麻烦会的朋友帮忙回复,谢啦

布局如下:
<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#F8F8F8"
     android:orientation="vertical" >
     <LinearLayout
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:orientation="vertical" >
             
             <LinearLayout
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:orientation="vertical" >
             <RelativeLayout
                 android:id="@+id/registernumber_layout"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content" >
                 <TextView                          
                     android:textSize="20sp"
                     android:layout_centerVertical="true"                  
                     android:layout_width="wrap_content"
                     android:layout_height="45dp"
                     android:layout_alignParentLeft="true"
                     android:layout_marginLeft="15dp"
                     android:textColor="#707070"
                     android:layout_marginTop="15dp"
                     android:text="注册手机:" />
                 <TextView                          
                     android:textSize="20sp"
                     android:layout_centerVertical="true"                  
                     android:layout_width="wrap_content"
                     android:layout_height="30dp"
                     android:paddingLeft="110dp"
                     android:layout_marginTop="30dp"
                     android:textColor="#707070"
                     android:text="-" />
                 </RelativeLayout>
                 
                 <View
                     android:layout_width="fill_parent"
                     android:layout_height="1dip"
                     android:background="#eeeeee" />

                 <RelativeLayout
                     android:id="@+id/wodeshouchang_layout"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" >
                     <TextView
                         android:id="@+id/newnumber"
                      android:textSize="20sp"
                      android:layout_centerVertical="true"  
                      android:layout_alignParentLeft="true"                
                      android:layout_width="wrap_content"
                      android:layout_height="45dp"
                      android:textColor="#707070"
                      android:layout_marginLeft="15dp"
                      android:layout_marginTop="35dp"
                         android:text="新手机号:" />
                     <EditText
                      android:textSize="15sp"
                      android:paddingLeft="2dp"
                      android:layout_toRightOf="@id/newnumber"
                      android:layout_centerVertical="true"                  
                      android:layout_width="fill_parent"
                      android:layout_height="45dp"
                      android:layout_marginRight="15dp"
                      android:background = "@drawable/edittext_style"
                      android:textColor="#707070"
                        />
                 </RelativeLayout>
                 <View
                     android:layout_width="fill_parent"
                     android:layout_height="1dip"
                     android:background="#eeeeee" />
      
      
      。。。。。
     。。。。。(后面还有别的控件)

     
                </LinearLayout>
              </LinearLayout>           
         </LinearLayout>   
------解决思路----------------------
<RelativeLayout
                     android:id="@+id/wodeshouchang_layout"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" 
                     android:layout_centerVertical="true"  
>
                     <TextView
                         android:id="@+id/newnumber"
                      android:textSize="20sp"
                      android:layout_alignParentLeft="true"                
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:textColor="#707070"
                      android:layout_marginLeft="15dp
                         android:text="新手机号:" 
                         android:textSize="15sp"
                       android:padding="10dp"
/>
                     <EditText
                      android:textSize="15sp"
                      android:paddingLeft="2dp"
                      android:layout_toRightOf="@id/newnumber"               
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginRight="15dp"
                      android:background = "@drawable/edittext_style"
                      android:textColor="#707070"
                     android:padding="10dp"
                        />
                 </RelativeLayout>
写代码要注意一点,尽量不要指定控件的宽高,你这里可以通过字体大小和margin和padding来控制距离,上面的我没试过,不过应该可以了吧。。
------解决思路----------------------
用relativelayout,设置属性: android:layout_centerVertical="true"
------解决思路----------------------
在LinearLayout里加上android:gravity="center_vertical"
  相关解决方案