119

私は以下のような私のレイアウトを持っています:

<?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:orientation="vertical" >

<TextView
        android:id="@+id/textView1"
        style="@style/behindMenuItemLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Twitter Feeds"
        android:textStyle="bold" />

    <ListView
        android:id="@+id/list"
        android:layout_width="350dp"
        android:layout_height="50dp" />

    <TextView
        android:id="@+id/textView1"
        style="@style/behindMenuItemLabel1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:text="FaceBook Feeds" />

    <ListView
        android:id="@+id/list1"
        android:layout_width="350dp"
        android:layout_height="50dp" />

</LinearLayout>

私の要件は、 と の間に水平線を引くことですTextViewListView

誰でも助けてもらえますか?

4

18 に答える 18

313

との間にシルバーグレーの線を描画しTextViewますListView

<TextView
    android:id="@+id/textView1"
    style="@style/behindMenuItemLabel1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="1dp"
    android:text="FaceBook Feeds" />

<View
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:background="#c0c0c0"/>

<ListView
    android:id="@+id/list1"
    android:layout_width="350dp"
    android:layout_height="50dp" />
于 2013-10-01T11:49:46.740 に答える
24

Space分割線を描画するには、新しい軽量ビューを使用する必要があります。Spaceの代わりに使用すると、レイアウトの読み込みが速くなりますView

横仕切り:

<android.support.v4.widget.Space
        android:layout_height="1dp"
        android:layout_width="match_parent" /> 

垂直分割線:

<android.support.v4.widget.Space
        android:layout_height="match_parent"
        android:layout_width="1dp" />

背景を追加することもできます:

<android.support.v4.widget.Space
        android:layout_height="match_parent"
        android:layout_width="1dp"
        android:background="?android:attr/listDivider"/>

使用例:

....
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="One"/>

<android.support.v4.widget.Space
    android:layout_height="match_parent"
    android:layout_width="1dp"
    android:background="?android:attr/listDivider"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Two"/>

<android.support.v4.widget.Space
    android:layout_height="match_parent"
    android:layout_width="1dp"
    android:background="?android:attr/listDivider"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Three"/>
....

使用するには、 build.gradleSpaceに依存関係を追加する必要があります。

dependencies {
    compile 'com.android.support:support-v4:22.1.+'
}

ドキュメントhttps://developer.android.com/reference/android/support/v4/widget/Space.html

于 2015-05-26T15:42:14.420 に答える
19

一度作成して、必要な場所で使用することをお勧めします。これを styles.xml に追加します。

<style name="Divider">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">1dp</item>
    <item name="android:background">?android:attr/listDivider</item>
</style>

行区切りが必要な xml コードにこれを追加します。

<View style="@style/Divider"/>

この質問に対する toddles_fp の最初の回答: Android Drawing Separator/Divider Line in Layout?

于 2016-08-26T07:44:08.977 に答える
12

これを試して

<View
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:background="?android:attr/listDivider"/>
于 2015-08-31T13:20:33.050 に答える
6
<View
       android:id="@+id/view"
       android:layout_width="match_parent"
       android:layout_height="2dp"
       android:background="#000000" />
于 2013-10-01T11:55:36.083 に答える
2

このビューをビューの間に配置して、線を模倣できます

<View
  android:layout_width="fill_parent"
  android:layout_height="2dp"
  android:background="#c0c0c0"/>
于 2015-08-10T13:17:34.137 に答える
1

LinearLayoutコンポーネント間の仕切りが必要な各親に、android:divider="?android:dividerHorizontal"またはを追加しandroid:divider="?android:dividerVerticalます。

の向きに応じて、適切なものを選択してくださいLinearLayout

このリソース スタイルは、Android 4.3 から追加されたものです。

于 2013-10-01T12:32:01.627 に答える
1

これを試して

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/darker_gray"/>
于 2015-11-30T12:57:28.967 に答える
0

--> シンプルなもの

 <TextView
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#c0c0c0"
    android:id="@+id/your_id"
    android:layout_marginTop="160dp" />
于 2016-02-09T11:47:18.253 に答える
0

下線のためだけに余分なビューを使用したくない場合。このスタイルを に追加しますtextView

style="?android:listSeparatorTextViewStyle"

ただ欠点は、次のような追加のプロパティを追加することです

android:textStyle="bold"
android:textAllCaps="true"

簡単にオーバーライドできます。

于 2016-01-12T02:38:27.630 に答える