2011-11-30 18 views
15
<LinearLayout 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:orientation="vertical" android:background="@drawable/settings_border" android:padding="1dp" 
      android:layout_marginLeft="15dip" android:layout_marginRight="15dip" android:layout_marginTop="5dip"> 
      <RelativeLayout android:id="@+id/map_refresh" 
       android:layout_height="fill_parent" android:layout_width="wrap_content" 
       android:background="@drawable/settings_selector_up" 
       android:padding="15dp"> 
       <TextView android:id="@+id/Text1" 
        android:layout_height="wrap_content" android:layout_width="wrap_content" 
        android:text="Map refresh period"> 
       </TextView> 
       <TextView android:id="@+id/TextView09" 
        android:layout_height="wrap_content" android:layout_width="wrap_content" 
        android:text="1 min" 
        android:layout_alignParentRight="true" 
        android:paddingRight="5dp"> 
       </TextView> 
      </RelativeLayout> 

      <RelativeLayout android:id="@+id/own_location" 
       android:layout_height="fill_parent" android:layout_width="wrap_content" 
       android:padding="15dp" 
       android:background="@drawable/settings_selector_mid"> 
       <TextView android:id="@+id/Text1" 
        android:layout_height="wrap_content" android:layout_width="wrap_content" 
        android:text="Own location update period"> 
       </TextView> 
       <TextView android:id="@+id/TextView09" 
        android:layout_height="wrap_content" android:layout_width="wrap_content" 
        android:text="1 min" 
        android:layout_alignParentRight="true" 
        android:paddingRight="5dp"> 
       </TextView> 
      </RelativeLayout> 

relativelayoutでボトムボーダーのみを設定します。私はlistviewスタイルをディスパッチしたいが、listviewは使わない。それぞれのリスト項目が相対的なものであると言います。私はリストビューのディバイダのように見えるので、下の境界線のみを設定します。relativelayoutのボトムボーダーの追加方法

+0

はここで非常に類似した質問に対する私の答えだ:私はここからアイデアを得た

<LinearLayout android:id="@+id/searchWrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="5dp" android:paddingBottom="5dp" android:background="@drawable/bottom_gray_border" android:layout_alignParentTop="true"> <EditText android:id="@+id/searchEditText" style="@style/EditTextSearch" android:hint="@string/find" android:layout_marginLeft="5dp"/> </LinearLayout> 

これは次のようにレイアウトXMLがどのように見えるかです。軽量で簡単なライブラリで問題を解決しました。 http://stackoverflow.com/a/30802089/3649279 – PAD

+0

ここをクリックしてください[BorderedRelativeLayout](https://stackoverflow.com/a/45959525/6258971) – suulisin

答えて

12

あなたの言ったことを理解してくれることを願っています。解像度フォルダ内の

(あなたはすでにそれを持っていない場合)に新しいフォルダを作成するには、あなたはさらにそれを編集することができます「borders.xml」

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_pressed="true"><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
     <gradient android:angle="90" android:centerColor="#6da23f" android:endColor="#8bc45d" android:startColor="#2f481c" /> 

      <stroke android:width="2dp" android:color="#999999" /> 

      <padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" /> 

      <corners android:radius="10px"/> 
     </shape> 
    </item> 
    <item> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
      <gradient android:angle="90" android:centerColor="#6da23f" android:endColor="#8bc45d" android:startColor="#4c8a39" /> 

      <stroke android:width="1dp" android:color="#FFFFFF" /> 

      <padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" /> 

      <corners android:radius="10px"/> 
     </shape> 
    </item> 
</selector> 

という名前のXMLを作成してそこに描画可能

の名前好きなように。 アウトラインからレイアウトを選択し、背景のプロパティをクリックし、作成した罫線xmlを選択します。

これは、単純な

<View android:layout_width="1dip" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF" /> 

行を追加し、レイアウトの一番下に追加し、お好みに合わせて色/サイズを変更することができ、またすべての4のための境界線を作成します。

+9

これは4つの罫線を全て下に表示するのではなく、見えるようにします。 –

0

境界を表示する簡単な方法は、水平LinearLayoutを作成し、必要な境界線に従って背景色と高さを設定することです。

+1

私はそれが良い考えだとは思わない:LinearLayout国境を作るために使われることを意図していません... – mithrop

+0

いいえ、これは良い方法ではありません –

+0

簡単な方法です、あなたはあなたの国境にいくつかのプロパティを取得します。 – Charleston

8
<?xml version="1.0" encoding="UTF-8"?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke 
     android:width="1dip" 
     android:color="#FF8000" /> 

    <solid 
     android:color="#00FFFFFF" 
     android:paddingLeft="10dip" 
     android:paddingTop="10dip"/> 

    <corners android:radius="10px"/> 

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

あなたは(それがまだ存在してdoesntの場合は作成)のres /描画可能なフォルダにborderframe.xmlとしてこれを保存し、そのようにそれを参照することができます。android:background="@drawable/borderframe"

10

何らかの理由で、他の解決策が私のために機能しませんでした。どのように変更しても、すべての境界が表示されました。これは、仕事:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
     <shape 
      android:shape="rectangle"> 
      <stroke android:width="1dp" android:color="@color/gray" /> 
      <solid android:color="@color/gray" /> 
     </shape> 
    </item> 

    <item android:bottom="1dp"> 
     <shape 
      android:shape="rectangle"> 
      <stroke android:width="1dp" android:color="@color/white" /> 
      <solid android:color="@color/white" /> 

     </shape> 
    </item> 
</layer-list> 

(私の例でのLinearLayout)ボーダーの色は灰色あり、背景がコンテナの白です。 2番目の項目を変更するだけで、境界線を太くするか、上下左右に境界線を設定することができます。 Is there an easy way to add a border to the top and bottom of an Android View?

+0

私にとって完璧に動作します – akohout

+0

私はちょうど下のボーダーを追加したい、それは4つのボーダーをすべて追加しました。 –

+0

これは私のために働いたものです、ついに、ありがとう! – OneThreeSeven

関連する問題