其實我正在一個佈局中,我必須將CardView放在ImageView上,它只覆蓋ImageView的一半部分,並添加一個TextView(Check Attach Image) 。如何創建此視圖(佈局)
注:
- 我嘗試使用的FrameLayout,並與相對佈局... 和我實現它,但我不認爲這是一個正確的做法,因爲我硬編碼大多paramters。
XML代碼:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_gravity="center"
android:background="@drawable/background"
android:id="@+id/picture">
</ImageView>
<TextView
android:text="TEXT VIEW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="149dp"
android:layout_marginStart="149dp"
android:layout_marginTop="24dp"
android:id="@+id/textView" />
</FrameLayout>
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardBackgroundColor="@color/textViewBackground"
card_view:cardUseCompatPadding="true"
android:layout_centerHorizontal="true"
card_view:cardElevation="15sp"
android:layout_marginTop="153dp" />
您是否嘗試過這樣做嗎?如果是,那麼發佈的XML代碼 – Vishwa
請檢查我的代碼 –
嗨,兄弟你已經在你的代碼中給出了硬編碼的邊際 –