Android dynamic screen sharing

What am I trying to do?

Activity starts with ImageViewthe top 9/10 of the screen, and the ListViewrest is lower 1/10: enter image description here

As the number of elements added to increases ListView, the ratio changes, ListViewgets 1/10 more of the screen for each element, and ImageViewdecreases accordingly, to 50:50 (adds more elements after which fixes the ratio): enter image description here

: , LinearLayout android:weightSum ( View android:layout_weight). , AbsListView.LayoutParams, - ArrayAdapter. (). , ( Property Animation).

:

  • getWindowManager() .getDefaultDisplay().getHieght(); ?

  • , - , ArrayAdapter.registerDataSetObserver()?

+4
2

- , :

1) :

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

    <LinearLayout
        android:id="@+id/ll_forImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />    
    </LinearLayout>
    <LinearLayout
        android:id="@+id/ll_forList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </ListView>    
    </LinearLayout>
</LinearLayout>

2) .

private int dpToPx(int dp) {
    return (int) (dp * getResources().getDisplayMetrics().density + 0.5f);
}

private static void setLayoutSize(View view, int width, int height) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = width;
    params.height = height;
    view.setLayoutParams(params);
}

3) :

int screenWidth = dpToPx(getResources().getConfiguration().screenWidthDp);
int screenHeight = dpToPx(getResources().getConfiguration().screenHeightDp);
int ratio = ....;//
setLayoutSize(ll_forImage, screenWidth , screenHeight/ratio );
setLayoutSize(ll_forList, screenWidth , screenHeight - screenHeight/ratio );
+1

10% 90%, 1 9. xml-

+2

All Articles