2

私はアンドロイドが初めてで、次のようなビューを実装する必要があります。

-------------Some Text----------------------

View次のようなコードを使用して、xml で線を引くことができることを知っています。

<View
android:layout_width="100dp"
 android:layout_height="1dp"
 android:background="#00ff00" />

これにより、次のものが描画されます。

-----------------------

しかし、この後、テキストを配置して、線のもう一方の端をもう一度描きたいと思います。

試してみましたが、次のような結果が得られました。

----------------------
text

コードのTextView後に​​いくつか追加すると。View

私が目指していることは可能ですか?

前もって感謝します。

4

4 に答える 4

3

これは、あなたが望むものを手に入れるのに役立つかもしれません。ビューに重みを与えることが重要です..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >

<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_weight="1"
    android:background="#00ff00" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:background="#00ff00" />
</LinearLayout>
于 2013-02-28T10:51:06.370 に答える
2

FrameLayoutこの場合、またはRelativeLayout深いビュー階層を防ぎ、パフォーマンスを向上させるために使用してみてください

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff" >

<View
    android:layout_width="200dp"
    android:layout_height="1dp"
    android:layout_gravity="center"
    android:background="#555" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="#fff"
    android:text="Hello world" />

</FrameLayout>
于 2013-02-28T11:03:41.397 に答える
1

これを試して..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <View
        android:id="@+id/view1"
        android:layout_width="60dp"
        android:layout_height="4dp"
        android:layout_marginTop="5dp"
        android:background="#00ff00" />

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_toRightOf="@+id/view1"
        android:text="My Text" />

    <View
        android:id="@+id/view2"
        android:layout_width="60dp"
        android:layout_height="4dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/tv1"
        android:background="#00ff00" />

</RelativeLayout>

それがあなたのために働くことを願っています..

うまくいくかどうか教えてください。

于 2013-02-28T11:00:23.423 に答える
0

最も簡単な方法は、おそらく、RelativeLayout または水平方向の LinearLayout を使用して、線の幅を半分にし、次のように作成することです。

表示 (50 dp) - TextView - 表示 (50 dp)

于 2013-02-28T10:38:28.643 に答える