Scale background image to wrap content of layout

前端 未结 9 1838
执笔经年
执笔经年 2020-12-23 17:45

I have a layout that contains some text fields and has a background image that\'s displayed at the top of my activity. I\'d like the background image to scale to wrap the c

相关标签:
9条回答
  • 2020-12-23 18:21

    Try this code.....

    <LinearLayout 
       android:layout_width="fill_parent"
       android:id="@+id/HeaderList" 
       android:orientation="vertical"
       android:layout_gravity="top"
       android:layout_height="wrap_content" 
       android:background="@drawable/header">
    <TextView 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" 
        android:id="@+id/NameText"
        android:text="Jhn Doe" 
        android:textColor="#FFFFFF"
        android:textSize="30sp" 
        android:paddingLeft="4dp"
        android:paddingTop="4dp" 
    />
    <TextView 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" 
        android:textColor="#FFFFFF"
        android:id="@+id/HoursText"
        android:text="170 hours" 
        android:textSize="23sp" 
        android:paddingLeft="4dp" 
    />
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-23 18:22

    You can use this:

    <ImageView
    ...
    android:scaleType="fitXY"
    >
    

    Hope it helped)))

    0 讨论(0)
  • 2020-12-23 18:26

    You may try this trick,

    • FrameLayout (wrapcontent, wrapcontent)
      • ImageView (match parent, match parent) // its your background
      • LinearLayout (wrapcontent, wrapcontent)
        • All your contents goes inside this linear layout or any other type what ever you want
    0 讨论(0)
提交回复
热议问题