Dynamically set the height for scrollview
This commit is contained in:
parent
3419175299
commit
fc37aa24ed
3 changed files with 40 additions and 8 deletions
|
@ -47,7 +47,7 @@
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/cancel_row"
|
android:id="@+id/cancel_row"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="48dp"
|
android:layout_height="@dimen/snap_to_road_bottom_sheet_cancel_button_height"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
@ -155,4 +155,6 @@
|
||||||
<dimen name="my_places_empty_state_text_button_padding_left">48dp</dimen>
|
<dimen name="my_places_empty_state_text_button_padding_left">48dp</dimen>
|
||||||
<dimen name="my_places_empty_state_text_button_padding_right">60dp</dimen>
|
<dimen name="my_places_empty_state_text_button_padding_right">60dp</dimen>
|
||||||
<dimen name="my_places_empty_state_text_button_padding_top">64dp</dimen>
|
<dimen name="my_places_empty_state_text_button_padding_top">64dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="snap_to_road_bottom_sheet_cancel_button_height">48dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -1,17 +1,21 @@
|
||||||
package net.osmand.plus.measurementtool;
|
package net.osmand.plus.measurementtool;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -33,7 +37,7 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
||||||
final int backgroundColor = ContextCompat.getColor(getActivity(),
|
final int backgroundColor = ContextCompat.getColor(getActivity(),
|
||||||
nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||||
|
|
||||||
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_snap_to_road_bottom_sheet_dialog, container);
|
final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_snap_to_road_bottom_sheet_dialog, container);
|
||||||
view.setBackgroundColor(backgroundColor);
|
view.setBackgroundColor(backgroundColor);
|
||||||
if (nightMode) {
|
if (nightMode) {
|
||||||
((TextView) view.findViewById(R.id.cancel_row_text))
|
((TextView) view.findViewById(R.id.cancel_row_text))
|
||||||
|
@ -58,12 +62,33 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
||||||
navContainer.addView(row);
|
navContainer.addView(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
}
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
|
final int height = metrics.heightPixels;
|
||||||
|
|
||||||
private boolean hasNavBar() {
|
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
int id = getResources().getIdentifier("config_showNavigationBar", "bool", "android");
|
@Override
|
||||||
return id > 0 && getResources().getBoolean(id);
|
public void onGlobalLayout() {
|
||||||
|
final View scrollView = view.findViewById(R.id.navigation_types_scroll_view);
|
||||||
|
int scrollViewHeight = scrollView.getHeight();
|
||||||
|
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
|
||||||
|
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.snap_to_road_bottom_sheet_cancel_button_height);
|
||||||
|
int spaceForScrollView = height - getStatusBarHeight() - getNavBarHeight() - dividerHeight - cancelButtonHeight;
|
||||||
|
if (scrollViewHeight > spaceForScrollView) {
|
||||||
|
scrollView.getLayoutParams().height = spaceForScrollView;
|
||||||
|
scrollView.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
obs.removeOnGlobalLayoutListener(this);
|
||||||
|
} else {
|
||||||
|
obs.removeGlobalOnLayoutListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStatusBarHeight() {
|
private int getStatusBarHeight() {
|
||||||
|
@ -75,7 +100,7 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
||||||
return statusBarHeight;
|
return statusBarHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNavigationBarHeight() {
|
private int getNavBarHeight() {
|
||||||
if (!hasNavBar()) {
|
if (!hasNavBar()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -90,4 +115,9 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasNavBar() {
|
||||||
|
int id = getResources().getIdentifier("config_showNavigationBar", "bool", "android");
|
||||||
|
return id > 0 && getResources().getBoolean(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue