【问题标题】:android how to make some space between buttons and make white line above each of themandroid如何在按钮之间留出一些空间并在每个按钮上方制作白线
【发布时间】:2013-02-09 14:18:52
【问题描述】:

我有两个带有 xml 背景的按钮,我想在它们之间保留一些空间,因为它们彼此完全重叠,我也想在它们上方放置白线,我会告诉你我是如何尝试的,但它没有不和我一起工作

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"

    android:orientation="horizontal"

    android:weightSum="2" >

    <Button
        android:background="@drawable/button_selector"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:textStyle="bold"
        android:text="@string/b_save" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#FFFFFF"
        android:gravity="center"
        android:background="@drawable/button_selector"
        android:text="@string/b_cancel" />
</LinearLayout>

xml背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <padding android:top="10dip"
        android:bottom="10dip"/>



    <!-- Gradient Bg for listrow -->
    <gradient
        android:useLevel="false"
        android:angle="270"
        android:centerColor="#000000"
        android:endColor="#FFFFFF"
        android:startColor="#808080" />
</shape>

【问题讨论】:

    标签: android android-xml android-button


    【解决方案1】:

    看看这个

    bg_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    
        <padding android:top="10dip"
            android:bottom="10dip"/>
    
    
    
        <!-- Gradient Bg for listrow -->
        <gradient
            android:useLevel="false"
            android:angle="270"
            android:centerColor="#808080"
            android:endColor="#000000"
            android:startColor="#FFFFFF" />
    </shape>
    

    button_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    
        <padding android:top="10dip"
            android:bottom="10dip"/>
    
    
    
        <!-- Gradient Bg for listrow -->
        <gradient
            android:useLevel="false"
            android:angle="270"
            android:centerColor="#000000"
            android:endColor="#808080"
            android:startColor="#FFFFFF" />
    </shape>
    

    你的 xml

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dip"
        android:orientation="horizontal"
        android:background="@drawable/bg_selector"
        android:weightSum="2" >
    
        <Button
            android:background="@drawable/bg_selector"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#FFFFFF"
            android:gravity="center"
            android:textStyle="bold"
            android:layout_marginRight="4dip"
            android:layout_marginLeft="10dip"
            android:text="@string/b_save" />
    
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#FFFFFF"
            android:gravity="center"
            android:layout_marginLeft="4dip"
            android:layout_marginRight="10dip"
            android:background="@drawable/bg_selector"
            android:text="@string/b_cancel" 
            android:textStyle="bold"/>
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      在您的 XML 中使用以下代码来绘制 水平线

      <View
                      android:layout_width="match_parent"
                      android:layout_height="1dp"
                      android:layout_marginTop="5dp"
                      android:background="#ColorValue" />
      

      要绘制垂直线,只需更改 android:layout_widthandroid:layout_height.

      【讨论】:

      • 那是什么?我可以把它放在哪里?
      • 我需要一些东西放在后台 xml 中,因为我会使用它太多
      • 上面的代码会根据你提供的ColorValue画一条任意颜色的线。如果您在第一个按钮之后和第二个按钮之前的水平线性布局中使用它,它将在它们之间画一条线。同样,如果您在 Vertical LinearLayout 中使用它,它将在元素上方/下方绘制一条线。简单地说,用它在任何你想要的地方画一条线。
      • 好吧,我不认为你可以在你的 xml 背景中注入它。您必须将此代码复制并粘贴到要绘制线条的任何位置。
      • 嗯,是的.. 我绝对明白你的意思。我只是说我不知道​​如何通过将它放在背景 xml 中然后应用到所有元素来做到这一点。也许其他人可以帮助你。祝你好运! :)
      【解决方案3】:

      纯 1) android:layout_marginTop="10dp" 和
      2) xml 中的 android:layout_marginBottom="10dp" 这应该足够你的工作了,

      第一个点与顶部保持距离,第二个点与底部保持距离

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多