Reputation: 1911
I am trying to centerCrop my image but it doesn't seem to work. Here is the layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_block_list"
tools:context="com.contag.app.fragment.NavDrawerFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_drawer_header"
android:layout_width="match_parent"
android:layout_height="150dp">
<ImageView
android:id="@+id/iv_nav_drawer_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:background="@drawable/default_profile_pic"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_user_activity"
android:orientation="vertical"
android:paddingLeft="30dp">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_usr_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="@color/white"
android:text="Name"
android:textSize="20sp" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_usr_cunt_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_notification_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_blue"
android:padding="10dp">
<TextView
android:id="@+id/tv_notification_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:text="@string/notification"
android:textColor="@color/white"
android:onClick="onClick"
android:clickable="true"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have shortened the xml for posting here, specially the part which justifies for using a scrollView. What am I doing wrong?
Attached the output I am getting.
Upvotes: 0
Views: 130
Reputation: 4357
Change below code to :
<ImageView
android:id="@+id/iv_nav_drawer_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:background="@drawable/default_profile_pic"
/>
TO :
<ImageView
android:id="@+id/iv_nav_drawer_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/default_profile_pic"
/>
As per your requirement you have to set image view's width and height as wrap_content
and src
instead of background
.
Upvotes: 1