저는 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>