簡體   English   中英

如何在圖像上為android創建布局?

[英]How to create the layout for android as on image?

如何在圖像上為android創建布局?

布局圖

我嘗試下一個代碼:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="kkkkddd"
            android:layout_marginLeft="100dp"
            android:id="@+id/text_email" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/prompt_email"
            android:id="@+id/text_label_email"
            android:layout_toLeftOf="@id/text_email" />
        ...

但是label_email是隱藏的。

您應該先放置label-TextView並為其設置固定寬度。 比在標簽的右邊放置value-TextView:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="@string/prompt_email"
        android:id="@+id/text_label_email"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="kkkkddd"
        android:toRightOf="@id/text_label_email"
        android:id="@+id/text_email" />

嘗試將方向設為水平的線性布局:)

Imo LinearLayout更適合於此目的。 例如:

 <LinearLayout
    android:orienation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_weight="1"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="kkkkddd"
        android:layout_marginLeft="100dp"
        android:id="@+id/text_email" />

    <TextView
        android:layout_weight="1"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="@string/prompt_email"
        android:id="@+id/text_label_email"
        android:layout_toLeftOf="@id/text_email" />

</LinearLayout>

你可以為每一對做

制作父級Linearlayout。 並使用內部linearLayouts。 在內部布局中,使重力水平。 然后給兩個子項都賦予.5的權重,即“電子郵件” textview和“ utkin@gmail.com”的權重都應為.5。 為“電子郵件”設置右對齊,為“ utkin@gmail.com”設置左對齊。

它將完美運行。

投票或將其標記為真(如果有幫助)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM