[英]Set a bitmap as background and crop it
我正在嘗試將位圖圖像設置為FrameLayout的背景。
<FrameLayout
android:id="@+id/game_list_header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<LinearLayout
android:id="@+id/game_list_header_cnt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/game_list_header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/game_list_header_sub_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</FrameLayout>
這個問題是我想要設置為背景的圖像的高度大於兩個TextView的高度,因此game_list_header
的高度不適合TextView的高度而是ImageView高度。
我嘗試了不同的方法,例如使用位圖作為DrawableBitmap,使用gravity=clip_vertical|fill_horizontal
但即使這樣,圖像的高度也不適合TextView的高度,導致FrameLayout比我想要的大。
將FrameLayout的高度設置為,可能是40dp 。 由於您已將FrameLayout的高度設置為wrap_content ,因此XML也會考慮圖像的高度。
您是否嘗試將圖像設置為game_list_header_cnt
的背景?
如果沒有幫助,您可以簡單地使用ConstraintLayout
並imageView
top_top
頂部的textView
和bot_bot
機器人的textView
layout_height
的TextView
被設置為wrap_content
,因此的實際高度TextView
通過的TEXTSIZE確定TextView
。
你可以將FrameLayout
的layout_height
設置為一個數字,例如80dp,並將LinearLayout
layout_height
設置為match_parent
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.