簡體   English   中英

如何使用Card View Android在相對布局的中心添加垂直線?

[英]How to add vertical line in center of Relative layout using card view android?

我想使用較細的垂直線將相對布局分為兩部分。

這樣我就可以輕松地使用Card View使用相對布局的全寬。

我也想使我的卡片視圖可點擊,當我單擊特定的卡片視圖時,它將進入另一種布局並顯示有關單擊數據的所有詳細信息。

有人可以推薦或建議我進行即時貼視圖點擊嗎?

這是我的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:id="@+id/card_view"
    android:layout_marginBottom="3dp"
    app:cardBackgroundColor="@color/cardview_light_background">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:paddingBottom="10dp"
        android:id="@+id/rel_personal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Example Name"
            android:fontFamily="sans-serif-medium"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="15dp"
            android:layout_alignParentTop="true"
            android:id="@+id/person_name"
            android:textColor="#000000"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/person_name"
            android:text="example@gmail.com"
            android:fontFamily="sans-serif-light"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="5dp"
            android:id="@+id/person_email"
            android:textColor="#000000"/>

    </RelativeLayout>

</android.support.v7.widget.CardView>

要創建垂直分隔線,您可以在布局中的任何位置使用虛擬視圖,例如:

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

同樣,為了使cardView可點擊,您可以像使用任何其他類型的視圖一樣使用其setOnClickListener方法。

暫無
暫無

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

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