2016-08-19 4 views
-2

У меня есть вложенный профиль внутри CoordinatorLayout. Теперь в nestedScrollview есть 5-6 просмотров, и visibilty изменится в зависимости от данных, доступных через сеть. Проблема в том, что scrollview всегда занимает одну и ту же высоту (всего из всех 5-6 просмотров) и оставляет пустое место внизу, когда я скрываю видимость любого вида. Может кто-нибудь, пожалуйста, скажите мне, как я могу перенастроить высоту прокрутки, поэтому в нижней части прокрутки нет пробела.Динамическая регулировка высоты прокрутки Android

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/MyAppbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:collapsedTitleGravity="center_horizontal" 
     app:expandedTitleGravity="center_horizontal" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <!--Some content here--> 

    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 

     <include 
      android:id="@+id/profile_extra_details" 
      layout="@layout/profile_extra_details_layout" /> 

     <LinearLayout 
      android:id="@+id/see_project_listing_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 

      <include layout="@layout/divider" /> 

      <ViewSwitcher 
       android:id="@+id/work_switcher" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <include 
        android:id="@+id/see_project_listing" 
        layout="@layout/photos_with_heading" /> 

       <TextView 
        android:id="@+id/txt_no_work_found" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_gravity="center" 
        android:gravity="center" 
        android:text="There are no Design Boards" 
        /> 
      </ViewSwitcher> 

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

Это NestedScrollview. Ниже приведен профиль_extra_details_layout. Это макет, чья видимость контролируется на основе доступности данных из сети, а также тип пользователя, чей профиль просматривается.

<?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="wrap_content" 
    android:orientation="vertical"> 

    <include layout="@layout/divider" /> 

    <TextView 
     android:id="@+id/user_description" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/activity_horizontal_margin" 
     android:layout_marginRight="@dimen/activity_horizontal_margin" 
     android:visibility="gone" /> 

    <LinearLayout 
     android:id="@+id/location_buget_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:gravity="center" 
     android:orientation="horizontal" 
     android:visibility="visible"> 

     <LinearLayout 
      android:id="@+id/ll_budget_yearEstb" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="vertical" 
      android:visibility="gone"> 

      <ImageView 
       android:id="@+id/img_budget_yearEstb" 
       android:layout_width="60dp" 
       android:layout_height="60dp" 
       android:layout_gravity="center_horizontal" 
       android:src="@drawable/id_proejct_budget" /> 

      <TextView 
       android:id="@+id/txt_budget_yearEstb" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/ll_location" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="vertical" 
      android:visibility="gone"> 

      <ImageView 
       android:layout_width="60dp" 
       android:layout_height="60dp" 
       android:layout_gravity="center_horizontal" 
       android:padding="5dp" 
       android:src="@drawable/id_project_city" /> 

      <TextView 
       android:id="@+id/location" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:padding="5dp" 
       android:text="Mumbai,India" 
       android:textStyle="bold" /> 
     </LinearLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/individual_firm_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:orientation="horizontal" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:visibility="gone"> 

     <ImageView 
      android:layout_width="@dimen/image_size_beside_text" 
      android:layout_height="@dimen/image_size_beside_text" 
      android:src="@drawable/id_expert_firm_ind" /> 

     <TextView 
      android:id="@+id/individual_firm_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Firm/Individual" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/awards_ll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:orientation="horizontal" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:visibility="gone"> 

     <ImageView 
      android:layout_width="@dimen/image_size_beside_text" 
      android:layout_height="@dimen/image_size_beside_text" 
      android:src="@drawable/id_expert_awards" /> 

     <TextView 
      android:id="@+id/awards_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/web_add_ll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:visibility="gone"> 

     <ImageView 
      android:layout_width="@dimen/image_size_beside_text" 
      android:layout_height="@dimen/image_size_beside_text" 
      android:src="@drawable/id_seller_web" /> 

     <TextView 
      android:id="@+id/web_add_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Abc.xyz" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/ll_location_ho" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:visibility="gone"> 

     <ImageView 
      android:layout_width="@dimen/image_size_beside_text" 
      android:layout_height="@dimen/image_size_beside_text" 
      android:src="@drawable/id_project_city" /> 

     <TextView 
      android:id="@+id/location_ho_txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Abc.xyz" /> 
    </LinearLayout> 
</LinearLayout> 

Пожалуйста, дайте мне знать, если мне нужно уточнить больше в любом месте.

+0

Без каких-либо кодов или структуры изображения или что-то еще, мы не сможем вам помочь. Вот почему люди не заботятся об этом. – Cyrex

+0

Попробуйте это, но не гарантируйте, будет ли это исправление в вашем случае. http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/ – Cyrex

ответ

0

Это поможет вам: когда вы скрываете свое мнение использование View.GONE, я думаю, что вы используете View.INVISIBLE

+0

Нет, я использую View.GONe только. Я не хочу View.INVISIBLE, потому что это создаст пустое пространство в середине макета. – user2601981

+0

Вы скрываете виды или линейный макет? потому что вы используете представления внутри линейного макета. – VNS

+0

Я скрываю оба представления, а также LinearLayout, если нет ничего, что можно было бы отображать внутри LinearLayout – user2601981

0

Попробуйте изменить nestedscrollview высоты match_parent и ребенок линейной высоты макета wrap_content. После этого по вашим данным изменяются видимость детского макета линейного макета во время выполнения.

Смежные вопросы