diff --git a/app/src/main/java/com/simplemobiletools/gallery/Utils.java b/app/src/main/java/com/simplemobiletools/gallery/Utils.java index 2310ed368..45351cece 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Utils.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Utils.java @@ -6,6 +6,7 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; +import android.util.TypedValue; import android.view.View; import android.view.Window; import android.widget.Toast; @@ -19,12 +20,28 @@ public class Utils { Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show(); } + public static int getActionBarHeight(Context context, Resources res) { + final TypedValue tv = new TypedValue(); + int height = 0; + if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { + height = TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); + } + return height; + } + + public static int getStatusBarHeight(Resources res) { + int id = res.getIdentifier("status_bar_height", "dimen", "android"); + if (id > 0) { + return res.getDimensionPixelSize(id); + } + return 0; + } + public static int getNavBarHeight(Resources res) { int id = res.getIdentifier("navigation_bar_height", "dimen", "android"); if (id > 0) { return res.getDimensionPixelSize(id); } - return 0; } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index c4a2d1412..7efdff1c4 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -343,18 +343,15 @@ public class ViewPagerActivity extends AppCompatActivity private void addUndoMargin() { final Resources res = getResources(); - final int height = Utils.getNavBarHeight(res); final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) undoBtn.getLayoutParams(); + final int topMargin = Utils.getStatusBarHeight(res) + Utils.getActionBarHeight(getApplicationContext(), res); int rightMargin = params.rightMargin; - int bottomMargin = params.bottomMargin; - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - bottomMargin = height; - } else { - rightMargin = height; + if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT) { + rightMargin += Utils.getNavBarHeight(res); } - params.setMargins(params.leftMargin, params.topMargin, rightMargin, bottomMargin); + params.setMargins(params.leftMargin, topMargin, rightMargin, params.bottomMargin); } @Override diff --git a/app/src/main/res/layout/activity_medium.xml b/app/src/main/res/layout/activity_medium.xml index 4edfd536b..ff8eb2e52 100644 --- a/app/src/main/res/layout/activity_medium.xml +++ b/app/src/main/res/layout/activity_medium.xml @@ -13,10 +13,10 @@