2017-07-21 25 views
0

我使用CircularImageView來設置人物的個人資料圖片。出於某種原因,我無法弄清楚爲什麼圖像的佔位符未顯示在配置文件屏幕中。當用戶沒有設置任何配置文件圖像時,圖像的佔位符完全不顯示。但是當我使用相機或畫廊意圖在同一頁面中設置圖像時,它會在佔位符中顯示圖像。我無法找出問題所在。當用戶在配置文件CircularImageView中沒有任何圖像時,請幫助我爲什麼它不顯示默認的src屬性。src drawable不顯示在屏幕上

發佈下面的xml文件。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:layout_editor_absoluteX="8dp" 
tools:layout_editor_absoluteY="8dp"> 

<android.support.constraint.ConstraintLayout 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    tools:context="com.project.group.projectga.fragments.ProfileFragment"> 


    <android.support.constraint.ConstraintLayout 
     android:id="@+id/photoLayout" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"> 

     <ImageView 
      android:id="@+id/profileBackground" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:scaleType="fitCenter" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      app:srcCompat="@drawable/profile_background" 
      tools:ignore="ContentDescription" /> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="8dp" 
      android:layout_marginEnd="8dp" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="8dp" 
      android:orientation="horizontal" 
      android:padding="10dp" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/photoCircle"> 

      <mehdi.sakout.fancybuttons.FancyButton 

       android:id="@+id/cameraButton" 
       style="@style/fancyButtonProfile" 
       app:fb_defaultColor="@color/colorPrimary" 
       app:fb_radius="30dp" 
       app:fb_text="Camera" 
       app:fb_textSize="15sp" /> 

      <mehdi.sakout.fancybuttons.FancyButton 
       android:id="@+id/galleryButton" 
       style="@style/fancyButtonProfile" 
       android:layout_marginStart="10dp" 
       android:layout_toEndOf="@+id/cameraButton" 
       app:fb_defaultColor="@color/colorPrimary" 
       app:fb_radius="30dp" 
       app:fb_text="Gallery" 
       app:fb_textSize="15sp" /> 

      <mehdi.sakout.fancybuttons.FancyButton 
       android:id="@+id/removeButton" 
       style="@style/fancyButtonProfile" 
       android:layout_marginStart="10dp" 
       android:layout_toEndOf="@+id/galleryButton" 
       app:fb_borderColor="@color/colorPrimary" 
       app:fb_borderWidth="2dp" 
       app:fb_defaultColor="@android:color/transparent" 
       app:fb_radius="30dp" 
       app:fb_text="Remove" 
       app:fb_textColor="@color/colorPrimary" /> 

     </RelativeLayout> 

     <android.support.constraint.ConstraintLayout 
      android:id="@+id/photoCircle" 
      android:layout_width="128dp" 
      android:layout_height="128dp" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent"> 

      <com.mikhaellopez.circularimageview.CircularImageView 
       android:id="@+id/circularPhoto" 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_centerInParent="true" 
       android:cropToPadding="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/ic_account_circle_white_24dp" 
       app:civ_shadow="true" 
       app:civ_shadow_radius="24" 
       app:layout_constraintBottom_toBottomOf="parent" 
       app:layout_constraintHorizontal_bias="0.0" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toTopOf="parent" 
       app:layout_constraintVertical_bias="0.0" /> 


     </android.support.constraint.ConstraintLayout> 

    </android.support.constraint.ConstraintLayout> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/aboutDividerLayout" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="24dp" 
     android:layout_marginStart="24dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/photoLayout"> 

     <ImageView 
      android:id="@+id/aboutDivider" 
      android:layout_width="336dp" 
      android:layout_height="2dp" 
      android:background="@color/md_grey_300" 
      android:scaleType="fitXY" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      app:srcCompat="@android:drawable/divider_horizontal_bright" 
      tools:ignore="ContentDescription" /> 

     <TextView 
      android:id="@+id/aboutLabel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="8dp" 
      android:layout_marginEnd="8dp" 
      android:layout_marginStart="8dp" 
      android:layout_marginTop="8dp" 
      android:background="@color/md_light_background" 
      android:paddingLeft="8dp" 
      android:paddingRight="8dp" 
      android:text="@string/aboutLabel" 
      android:textAlignment="center" 
      android:textColor="@color/accent" 
      android:textSize="12sp" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" /> 

    </android.support.constraint.ConstraintLayout> 

這是用戶第一次創建時的圖像。

First Time user profile

這是後的圖像是使用庫後設置個人資料圖片設置。

After image is set using Gallery Intent

非常感謝提前任何幫助表示讚賞。這是我加載圖片的片段

Picasso.with(getContext()).load(profile.getProfile()).error(R.drawable.ic_error_outline_black_24dp).into(circularProfilePhoto); 
+0

也許與寬度和高度爲0有關? 如果這不是你爲什麼不添加一個默認人並在用戶拍照時進行更改? – nKalai

+0

如果是寬度和高度,當我從圖庫和相機中設置圖像時,它也不會顯示。 –

回答

1

如果你的目標是要顯示默認的圖像,然後你可以設置從代碼中的默認圖像在活動/片段:

findViewById(R.id.circularPhoto).setBackgroundResource(R.drawable.chrysanthemum) 

android:background = "@drawable/ic_account_circle_white_24dp" 

attribute in xml。

我不明白爲什麼在XML中不顯示圖像,即使你使用了Android的命名SRC屬性用於顯示繪製。如果它會是其他名稱空間,那麼aapt將它視爲一個自定義屬性。我試圖用android:src屬性在我的代碼中顯示一個默認圖像,它工作正常。

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

<com.mikhaellopez.circularimageview.CircularImageView 
    android:id="@+id/circularImageView" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="20dp" 
    android:src="@drawable/chrysanthemum" 
    /> 

</LinearLayout> 

但是這一次沒有在XML中工作,而我需要從代碼中設置的圖像,使其工作:

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

<com.mikhaellopez.circularimageview.CircularImageView 
    android:id="@+id/circularImageView" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="20dp" 
    app:src="@drawable/chrysanthemum" 
    /> 

</LinearLayout> 

讓我知道它是否適合你。

+0

@Prashanth - 我不得不在片段中設置它,我不認真理解它爲什麼沒有從XML加載。謝謝! –