7

Androidスタジオで次のレイアウトを再作成しようとしています:

プレビュー画像

私はAndroidのことはかなり新しいので、最初にLinearLayoutを試してみましたが、これはおそらくそれでは不可能だと考えました。今、私は RelativeLayout を試しています。私はすでにこのブロックを色付きで作成しています:

        <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:background="@color/red_top">
        </RelativeLayout>

今、同じレイアウトの上部に1つのバー、下部に2つのバーが表示されているように、どのように分割できますか?同じ境界線を配置するにはどうすればよいですか?

4

5 に答える 5

20

これを行うには、次の xml コードを使用します。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/custom_toast_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#CD96CD"
        android:text="TEXT" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#CD96CD"
            android:text="TEXT" />

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:background="#000000" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#CD96CD"
            android:text="TEXT" />
    </LinearLayout>

</LinearLayout>
于 2013-08-26T13:17:07.820 に答える
1

これを試して、追加の TextViews を追加できます

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#CD96CD"
    android:text="TEXT" />

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#000000" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#CD96CD"
        android:text="TEXT" />
     <View
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:background="#000000" />
     <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#CD96CD"
        android:text="TEXT" />

    <View
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:background="#000000" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#CD96CD"
        android:text="TEXT" />
     <View
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:background="#000000" />
     <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#CD96CD"
        android:text="TEXT" />
</LinearLayout>

于 2013-08-27T03:51:20.193 に答える
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" >

<LinearLayout 
    android:id="@+id/FirstLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/FirstTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TEXT_ONE" />
</LinearLayout>
<LinearLayout
    android:id="@+id/SecondLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/FirstLinearLayout"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/SecondTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TEXT_TWO" />

    <TextView
        android:id="@+id/ThirdTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TEXT_Three" />
</LinearLayout>

まず、すべてのコンポーネントを内部に保持するコンテナが必要です。私の例では、私が話しているコンテナはRelativeLayout. 相対レイアウトを使用すると、対応する ID を使用して子をその位置に配置できます。LinearLayoutを使用して他の 2 つの をどのように配置したかを見てくださいandroid:layout_below="@+id/FirstLinearLayout"

それらを同じレイアウトに配置したい場合は、相対レイアウトを使用して、TextView次のように配置します。

<?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" >


    <TextView
        android:id="@+id/FirstTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TEXT_ONE" />


    <TextView
        android:id="@+id/SecondTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/FirstTextView"
        android:text="TEXT_TWO" />

    <TextView
        android:id="@+id/ThirdTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/FirstTextView"
        android:layout_toRightOf="@+id/SecondTextView"
        android:text="TEXT_Three" />


</RelativeLayout>

これがお役に立てば幸いです。

于 2013-08-26T13:18:13.657 に答える
1

ATableLayoutは、ニーズを達成するための最良のオプションです。

<TableLayout>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="Text" />

    </TableRow>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

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

    </TableRow>
</TableLayout>

2 つの列にまたがるlayout_span最初の列で使用される属性に注意してください。TextView

于 2013-08-26T13:18:52.780 に答える
0

このビューを追加します。テキストビューの間にセパレーターを描画します

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#000000" />
于 2016-12-19T14:21:04.530 に答える