2014-09-06 7 views
0

J'ai un tiroir de navigation (menu coulissant) avec l'en-tête défini dans mon application. Je suis d'essayer ce qui suit pour la headerView.xmlImageView sur une autre imageview dans Android

enter image description here

Je suis en train une image d'arrière-plan à l'relativeLayout à partir d'une URL particulière. Au lieu de cela je voudrais avoir ImageView comme ci-dessous:

En faisant cela, je peux utiliser la bibliothèque Picasso même pour l'image de fond que je reçois d'une URL. De cette façon, le chargement d'images est plus rapide que je ne ai pas besoin de sauver l'arrière-plan à une carte SD etc.

enter image description here

Voici ce que j'ai en ce moment:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LayoutforbgImage" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:adjustViewBounds="true" 
    android:baselineAligned="false" 
    android:orientation="horizontal" > 

<LinearLayout 
    android:id="@+id/LinearLayoutforImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="10dp" 
    android:paddingLeft="5dp" 
    android:paddingTop="10dp" 
    tools:ignore="RtlSymmetry,RtlHardcoded" > 

    <ImageView 
     android:id="@+id/imageforprofile" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:src="@drawable/profilepic" /> 
</LinearLayout> 

<TextView 
    android:id="@+id/textforprofile" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/LinearLayoutforImage" 
    android:gravity="left" 
    android:paddingLeft="5dp" 
    android:paddingTop="16dp" 
    android:text="My Name My Name" 
    android:textColor="#FFFFFF" 
    android:textStyle="bold" 
    tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> 

<TextView 
    android:id="@+id/textforprofileemail" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textforprofile" 
    android:layout_toRightOf="@+id/LinearLayoutforImage" 
    android:gravity="left" 
    android:paddingBottom="10dp" 
    android:paddingLeft="5dp" 
    android:text="[email protected]" 
    android:textColor="#FFFFFF" 
    android:textStyle="bold" 
    tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> 

    </RelativeLayout> 

Je suis en train de fond à l'image mise en page pour: LayoutforbgImage utilisant:

headerLayout = (RelativeLayout) header.findViewById(R.id.LayoutforbgImage); 
BitmapDrawable background = new BitmapDrawable(decodeBase64(coverimage)); 
headerLayout.setBackgroundDrawable(background); 

headerprofileimage = (ImageView) header.findViewById(R.id.imageforprofile); 
Picasso.with(this).load(profileImage).placeholder(R.drawable.profilepic).error(R.drawable.profilepic).into(headerprofileimage); 

Comment puis-je créer l'ImageView pour l'image d'arrière-plan afin qu'il adapte perf ectly dans la disposition spécifiée comme ci-dessus?

+0

est-il travaille avec la mise en arrière-plan pour la mise en page par rapport? c'est la seule façon que je pense au lieu d'utiliser une autre imageview –

+0

Cela fonctionne très bien avec la mise en arrière-plan relativeLayout .. Mais si je dois utiliser la bibliothèque picasso, alors je vais avoir besoin d'un ImageView pour cela? – TheDevMan

Répondre

1

Salut essayez le code suivant il vous aidera à je ne faisais pas de changement. J'ajoute simplement un ImageView à votre mise en page.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LayoutforbgImage" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:baselineAligned="false" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/your_image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/top_bar" /> 

    <LinearLayout 
     android:id="@+id/LinearLayoutforImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingBottom="10dp" 
     android:paddingLeft="5dp" 
     android:paddingTop="10dp" 
     tools:ignore="RtlSymmetry,RtlHardcoded" > 

     <ImageView 
      android:id="@+id/imageforprofile" 
      android:layout_width="60dp" 
      android:layout_height="60dp" 
      android:src="@drawable/images12" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/textforprofile" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/LinearLayoutforImage" 
     android:gravity="left" 
     android:paddingLeft="5dp" 
     android:paddingTop="16dp" 
     android:text="My Name My Name" 
     android:textColor="#FFFFFF" 
     android:textStyle="bold" 
     tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> 

    <TextView 
     android:id="@+id/textforprofileemail" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textforprofile" 
     android:layout_toRightOf="@+id/LinearLayoutforImage" 
     android:gravity="left" 
     android:paddingBottom="10dp" 
     android:paddingLeft="5dp" 
     android:text="[email protected]" 
     android:textColor="#FFFFFF" 
     android:textStyle="bold" 
     tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" /> 

</RelativeLayout> 
+0

L'image arrive très petite. Surprise c'est petit même après match_parent. Quel pourrait être le problème? – TheDevMan

+0

où avez-vous obtenu l'image de fond? – Francis

+0

Il s'agit d'une photo de couverture de google plus. – TheDevMan

2

Essayez cette mise en page je l'espère vous aidera

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:scaleType="fitXY" 
      android:src="@drawable/top_header_bg" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:orientation="horizontal" > 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dp" 
       android:src="@drawable/ic_launcher" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:layout_marginRight="20dp" 
       android:orientation="vertical" > 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="TextView" /> 

       <TextView 
        android:id="@+id/textView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="TextView" /> 

      </LinearLayout> 

     </LinearLayout> 

    </RelativeLayout> 

</LinearLayout> 
+0

Merci pour la réponse rapide. Juste sortir. Je vais essayer de vous le faire savoir bientôt. Merci! – TheDevMan

0

Essayez ainsi l'espoir qu'il va résoudre votre problème

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout 
     android:id="@+id/topBarRelative" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" > 

     <ImageView 
      android:id="@+id/imageHeader" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:adjustViewBounds="true" 
      android:cropToPadding="false" 
      android:src="@drawable/right_top_bg" /> 

     <ImageView 
      android:id="@+id/imageforprofile" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="9dp" 
      android:src="@drawable/ic_launcher" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="9dp" 
      android:layout_toRightOf="@+id/imageforprofile" 
      android:gravity="center" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/textforprofile" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="3dp" 
       android:text="My Name My Name" 
       android:textColor="#FFFFFF" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/textforprofileemail" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="[email protected]" 
       android:textColor="#FFFFFF" 
       android:textStyle="bold" /> 
     </LinearLayout> 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/topBarRelative" 
     android:layout_margin="8dp" 
     android:background="@drawable/content_bg" 
     android:orientation="vertical" > 
    </LinearLayout> 

</RelativeLayout> 

Capture d'écran d'Eclipse

+0

pouvez-vous expliquer sur la dernière partie de la mise en page linéaire? – TheDevMan

+0

@TheDevMan: dernier 'LinearLayout' est pour la section restante sauf' top bar' – kId

Questions connexes