2016-10-12 5 views
0

저는 retrofit 및 coordinatorlayout을 사용하고 있습니다. 모두 잘 작동하는 것 같지만 약간의 문제가 있습니다. 내가 원하는 것은 레이아웃이 응답이 성공하는 순간에 표시된다는 것입니다. 이런 이유로, 나는 응답 내에서 setContentView를 호출한다. (이것이 좋은 연습인지 아닌지는 모른다.)setContentView가 스크롤의 모든 정보를 표시하지 않습니다?

내 문제는이 방법이 효과가 있지만 레이아웃이 스크롤을 전혀하지 않는다는 것이다. 정보. 그는 텍스트의 마지막 줄을 자른다. oncreate 메서드에서 setContentView를 호출하면 coordinatorlayout의 스크롤이 모든 정보 표시로 표시되지만이 시나리오에서는 성공한 응답을 완료 할 때 모든 올바른 이미지와 텍스트 앞에 레이아웃 디자인을 표시 할 수 있습니다.

누군가이 문제를 해결할 수있는 방법을 알고 있습니까?

미리 감사드립니다

상세 클래스 :

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     apiCall(R.layout.detail); 
    } 

    private void apiCall(final int layout){ 
     Bundle extras = getIntent().getExtras(); 
     if (extras != null) { 
      id = extras.getString("id"); 
     } 

     ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class); 

     Call<Hostel> call = apiService.getHostelId(id); 
     call.enqueue(new Callback<Hostel>() { 
      @Override 
      public void onResponse(Call<Hostel> call, Response<Hostel> response) { 

       try { 
        if (response.code() == 200) { 
         setContentView(layout); 
         initView(response); 
         setToolbar(); 
        } else { 
         Toast.makeText(getApplication(), getResources().getString(R.string.no_conexion), Toast.LENGTH_SHORT).show(); 
        } 
       }catch (Exception e){ 
        Log.e(TAG, e.toString()); 
       } 
      } 
      @Override 
      public void onFailure(Call<Hostel> call, Throwable t) { 
       Log.e(TAG, t.toString()); 
      } 
     }); 
    } 

detail.xml이 따라야 할 좋은 연습입니다 나는이 onCreate()setContentView(your_layout) 을 수행하는 게 좋을 것

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/coordinator" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/app_bar" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:paddingTop="24dp"> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="19dp"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:padding="5dp"> 
        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="vertical" 
         android:paddingLeft="10dp" 
         android:paddingBottom="10dp" 
         android:paddingTop="5dp"> 
         <TextView 
          android:id="@+id/propertyName_detail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/description" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 
         <TextView 
          android:id="@+id/description_detail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          /> 
        </LinearLayout> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="19dp" 
       android:layout_marginLeft="19dp" 
       android:layout_marginRight="19dp"> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/address_1" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 
         <TextView 
          android:id="@+id/addres_one_detail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/> 
        </LinearLayout> 
        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/address_2" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 
         <TextView 
          android:id="@+id/addres_two_detail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/> 
        </LinearLayout> 
        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/city" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 
         <TextView 
          android:id="@+id/city_detail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/> 
        </LinearLayout> 
        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="horizontal"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="@string/county" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 
         <TextView 
          android:id="@+id/country_detail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/> 
        </LinearLayout> 
       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="19dp"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:padding="5dp"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/directions" 
         android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 
        <TextView 
         android:id="@+id/directions_detail" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"/> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 
     </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="256dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapser" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/image_detail" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@android:color/transparent" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:theme="@style/CustomActionBar" 
       /> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.CoordinatorLayout> 

답변

1

전화 setContentView은 사용자에게 보여 레이아웃을 시도합니다.

지금의 알파 = "1.0"눈에 보이는 뷰를 만들 = "0.0"만들어보기 보이지 않는

안드로이드 알파 : 당신은이 widget

안드로이드의 alpha 속성을 사용하여 관리 할 수 ​​있습니다 전화

CoordinatorLayout cL=(CoordinatorLayout)findViewById(R.id.coordinator); 
cL.setAlpha(0); 

oncreate과 점점 후 성공적인 응답은 그것을 visible을 좋아요 :

cL.setAlpha(1); 
0

. 당신은 사용자가 데이터를로드하는 유선 프레임 디자인을 준수하지 않으려면

, 데이터가 도착하면 당신은 단순히

progressBar.setVisibility(View.GONE); 

이를 호출 할 수 있습니다 오버레이 레이아웃을 넣어 ProgressBar 구성 요소를 사용해보십시오 네이티브 안드로이드 구성 요소 사용에 대한 일반적인 해결책입니다.

그렇지 않으면 처음에 GONE이되도록 scrollview 가시성 (코드에서 id = scroll)을 설정할 수 있습니다. 그런 다음 데이터가 성공적으로 도착하면 다시 눈으로 확인하십시오. 같은 뭔가 : 응답이 성공하면 oncreate에서

@Override 
public void onResponse(Call<Hostel> call, Response<Hostel> response) { 
    try { 
     if (response.code() == 200) { 
     yourScrollView.setVisibility(View.VISIBLE); 
     // Do the rest of the your implementation here; 

    } catch (Exception e) { 
    // Blah blah 
    } 
} 
관련 문제