1

NavigationDrawer 헤더에 일부 사용자 정보를 올바르게 표시하려하지만 어떤 이유로 일부 속성이 헤더에 두 번 표시됩니다 ("일부 이메일 또는 기타 정보"및 이미지 위에). 내가 잘못하고 무엇을해야하는지 가르쳐 주시겠습니까? 감사! 헤더에 대한 XML 여기 NavigationDrawer header네비게이션 헤더 표시/초기화되지 않음

됩니다 : 여기

NavigationDrawer 헤더의 스크린 샷이다

<?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="@dimen/nav_header_height" 
android:background="@drawable/side_nav_bar" 
android:gravity="bottom" 
android:orientation="vertical" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="16dp" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

<de.hdodenhof.circleimageview.CircleImageView 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/userImage" 
    android:layout_width="96dp" 
    android:layout_height="96dp" 
    app:civ_border_width="2dp" 
    app:civ_border_color="#FF000000"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/nav_header_vertical_spacing" 
    android:text="Some user" 
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="some email or other information" /> 

그리고 여기를 초기화하는 자바 코드의 일부이다 NaviationDrawer, 이미지로드 등 ... :

main method: 
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout); //gets drawer button 
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(//intializes toggle for navigationdrawer 
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    drawer.setDrawerListener(toggle); //sets toggle for navigationdrawer 

    navigationView = (NavigationView) findViewById(R.id.nav_view); //initializes list of items in navigationdrawer 
    navigationView.setNavigationItemSelectedListener(this); //sets listener for items in navigationdrawer 
    navigationView.getMenu().getItem(0).setChecked(true); //sets "Map" as checked 
    loadNavigationDrawerInfo(navigationView.inflateHeaderView(R.layout.nav_header_main)); 
    mLocationRequest = LocationRequest.create() 
      .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) 
      .setInterval(10 * 1000)  // 10 seconds, in milliseconds 
      .setFastestInterval(1 * 1000); // 1 second, in milliseconds 
    drawer.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View v, boolean hasFocus) { 
      Log.d("TAG", "hasFocus" + hasFocus); 
     } 
    }); 

    public void loadNavigationDrawerInfo(View headerlayout) { 
     Map config = new HashMap(); 
     config.put("cloud_name", "some cloud name"); 
     config.put("api_key", "some api key"); 
     config.put("api_secret", "some api secret api secret"); 
     Cloudinary cloudinary = new Cloudinary(config);  

     new DownloadImageTask((CircleImageView) headerlayout.findViewById(R.id.userImage)).execute("some valid URL with a jpg"); 
} 

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { 
     CircleImageView bmImage; 

     public DownloadImageTask(CircleImageView bmImage) { 
      this.bmImage = bmImage; 
     } 

     protected Bitmap doInBackground(String... urls) { 
      String urldisplay = urls[0]; 
      Bitmap mIcon11 = null; 
      try { 
       InputStream in = new java.net.URL(urldisplay).openStream(); 
       mIcon11 = BitmapFactory.decodeStream(in); 
      } catch (Exception e) { 
       Log.e("Error", e.getMessage()); 
       e.printStackTrace(); 
      } 
      return mIcon11; 
     } 

     protected void onPostExecute(Bitmap result) { 
      bmImage.setImageBitmap(result); 
      Log.d("TAG", "Done loading image"); 
     } 
    } 
둘 다 사용하는 경우 3,691,363,210

답변

1

이가된다 : 당신의 XML의

navigationView.inflateHeaderView(R.layout.nav_header_main);

app:headerLayout="@layout/drawer_header"을. 그 중 하나를 비활성화하십시오.

프로그래밍 방식으로 전자 메일을 변경하려는 경우 Xml 코드를 사용하여 안정적인 헤더보기가있는 경우 Java 코드를 사용하십시오.

+1

Perfect! XML에서 app : headerLayout을 제거하고 문제를 해결했습니다. 감사! – fedorp1

관련 문제