2017-07-21 5 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

事前にどうもありがとうと任意の助けが理解されます。

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

か:あなたの目的は、あなたがあなたの活動/フラグメントのコードからデフォルトの画像を設定することができ、デフォルトの画像を表示する場合、私はフラグメント

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

多分、幅と高さが0であることと関係がありますか? デフォルトの人物を追加して写真を撮ったときにその人物を変更しないのはなぜですか? – nKalai

+0

幅と高さの場合は、ギャラリーとカメラから画像を設定しても表示されません。 –

答えて

1

に画像をロードする場所です

android:background = "@drawable/ic_account_circle_white_24dp" 

xmlの属性。

画像がXMLで示されていない理由を私はあなたが描画可能を示すためSRC属性を持つアンドロイド名前空間を使用したにも関わらず、理解していません。それが他の名前空間だったのなら、それをカスタム属性と見なしてください。私は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> 

しかし、この1つは、むしろ、私はそれを動作させるためのコードから画像を設定する必要があり、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から読み込まれなかったのかを真剣には理解していない。ありがとう! –

関連する問題