【问题标题】:how to add seprater in between edittext and button如何在edittext和button之间添加分隔符
【发布时间】:2013-07-13 15:36:18
【问题描述】:

我如何在edittext和下面的按钮之间添加行分隔符是我的代码帮助我请我遵循本教程How to add (vertical) divider to a horizontal LinearLayout?对我没有帮助请我只想在edittext和按钮之间添加行分隔

 <RelativeLayout  

 android:layout_height="wrap_content"  
 android:background="#a8a8a8"
android:layout_width="fill_parent">  
<EditText  
    android:id="@+id/EditText01"  
    android:hint="Enter some text..."  
    android:layout_alignParentLeft="true"  
    android:layout_width="fill_parent"  
     android:background="#a8a8a8"
     android:paddingTop="15dp"
     android:hint="SEARCH SCHOOL BY NAME"
    android:layout_toLeftOf="@+id/Button01"  
    android:layout_height="wrap_content">

</EditText> 



<Button  
    android:id="@+id/Button01"  
    android:text="Press Here!"  
    android:layout_width="wrap_content"  
    android:layout_alignParentRight="true"  
    android:layout_height="wrap_content"></Button>  
 </RelativeLayout>  

【问题讨论】:

  • 查看我的更新答案!

标签: android


【解决方案1】:

您可以将&lt;View/&gt; 放在编辑文本和按钮之间,如下所示..

<View
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:background="@color/Gray" />

【讨论】:

    【解决方案2】:

    您使用的是相对布局,因此您可以在布局视图中调整间距。

    【讨论】:

      【解决方案3】:

      如果您使用线性布局,您可以选择设置分隔线及其间距。

      如果您在相对布局中需要它,您可以考虑创建一个视图并将其附加到编辑文本的底部并留有一些边距

      希望对你有帮助

      【讨论】:

      • 您使用的是相对的,因此您可以将您的视图相对于彼此放在任何位置
      【解决方案4】:

      请检查android:hint="SEARCH SCHOOL BY NAME"这里你会得到错误,因为你不能使用**android:hint=""**这个或任何其他属性两次!

      检查您的以下代码:

      <EditText  
          android:id="@+id/EditText01"  
          android:hint="Enter some text..."  
          android:layout_alignParentLeft="true"  
          android:layout_width="fill_parent"  
           android:background="#a8a8a8"
           android:paddingTop="15dp"
           android:hint="SEARCH SCHOOL BY NAME"
          android:layout_toLeftOf="@+id/Button01"  
          android:layout_height="wrap_content">
      

      所以改成:

      要么使用android:hint="Enter some text..."

      android:hint="SEARCH SCHOOL BY NAME"
      

      编辑:

      如果你仍然无法绘制分隔符

      试试

         <RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#a8a8a8" >
      
          <EditText
              android:id="@+id/EditText01"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_alignParentLeft="true"
              android:layout_toLeftOf="@+id/my_view"
              android:background="#a8a8a8"
              android:hint="Enter some text..."
              android:paddingTop="15dp" >
          </EditText>
      
          <View
              android:id="@+id/my_view"
              android:layout_width="5dp"
              android:layout_height="match_parent"
              android:layout_alignBottom="@+id/EditText01"
              android:layout_marginLeft="5dip"
              android:layout_marginRight="5dip"
              android:layout_toLeftOf="@+id/Button01"
              android:background="#fff" />
      
          <Button
              android:id="@+id/Button01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:text="Press Here!" >
          </Button>
      </RelativeLayout>
      

      【讨论】:

        【解决方案5】:

        使用LinearLayout 而不是RelativeLayout

        <?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="#000000"
        android:orientation="vertical" >
        
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#a8a8a8" >
        
            <ImageView
                android:id="@+id/test_button_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:src="@drawable/icon" >
            </ImageView>
        
            <TextView
                android:id="@+id/test_button_text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/test_button_image"
                android:layout_toRightOf="@+id/test_button_image"
                android:text="San Diego Unified"
                android:textColor="#ffffff"
                android:textSize="20sp" >
            </TextView>
        
            <TextView
                android:id="@+id/test_button_text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/test_button_text2"
                android:layout_below="@+id/test_button_text2"
                android:text="SCHOOL DISTRICT"
                android:textColor="#ffffff" >
            </TextView>
        </RelativeLayout>
        
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:orientation="horizontal" >
        
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_weight="1"
                android:ellipsize="end"
                android:gravity="left|center_vertical"
                android:singleLine="true"
                android:text="HEALTHY BODIES HEALTHY MINDS "
                android:textSize="12sp" />
        
            <ImageButton
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/facebook" />
        
            <ImageButton
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/twitter"
                android:text="Button Text" />
        </LinearLayout>
        
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#a8a8a8" >
        
            <EditText
                android:id="@+id/EditText01"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_toLeftOf="@+id/seperator"
                android:background="#a8a8a8"
                android:hint="SEARCH SCHOOL BY NAME"
                android:paddingTop="15dp" >
            </EditText>
        
            <View
                android:id="@+id/seperator"
                android:layout_width="1dp"
                android:layout_height="fill_parent"
                android:layout_alignBottom="@+id/Button01"
                android:layout_toLeftOf="@+id/Button01"
                android:background="@android:color/white" />
        
            <Button
                android:id="@+id/Button01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Press Here!" >
            </Button>
        </RelativeLayout>
        
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#a8a8a8" >
        
            <ImageView
                android:id="@+id/test_button_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:src="@drawable/icon" >
            </ImageView>
        
            <TextView
                android:id="@+id/test_button_text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/test_button_image"
                android:layout_toRightOf="@+id/test_button_image"
                android:m=""
                android:text="San Diego Unified"
                android:textColor="#ffffff"
                android:textSize="20sp" >
            </TextView>
        </RelativeLayout>
        

        【讨论】:

        • 这是我的完整代码帮助我如何在edittext和按钮之间放置分隔符
        • 看看,我加了分隔符
        • @IonAalbers 你怎么能两次使用相同的属性? android:hint="Enter some text..." android:hint="SEARCH SCHOOL BY NAME" 更多说明请看我的回答!
        猜你喜欢
        • 2015-12-08
        • 1970-01-01
        • 2018-08-24
        • 2019-07-08
        • 1970-01-01
        • 2012-10-14
        • 2012-12-06
        • 2016-04-06
        • 1970-01-01
        相关资源
        最近更新 更多