sci*_*fic 0 android android-actionbar android-4.4-kitkat
我的Android应用中有自定义相机活动.对于使用KitKat的Android设备,我需要考虑屏幕底部的可见导航栏.为此,我使用以下行来确保我的视图位于导航栏下方:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN );
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,我的一个视图隐藏在操作栏后面.我试图通过在此视图中添加上边距来说明操作栏的高度,但它似乎不正确.
我究竟做错了什么?
这就是我希望视图看起来像(适用于预KitKat设备):

这就是Kit Kat设备目前的样子(你可以看到我视图的顶部被截断):

这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/gallery_scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY" >
<com.example.helperClass.PictureHorizontalLayout
android:id="@+id/mygallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scaleType="fitXY" >
</com.example.helperClass.PictureHorizontalLayout>
</HorizontalScrollView>
<FrameLayout
android:id="@+id/camerapreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black" />
<LinearLayout
android:id="@+id/button_holder_customized_cam"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:background="#838B8B"
android:gravity="bottom"
android:orientation="horizontal"
android:weightSum="0.9"
>
<ImageButton
android:id="@+id/gallery_customized_camera"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="1dp"
android:layout_weight="0.3"
android:adjustViewBounds="true"
android:background="@null"
android:contentDescription="@string/add"
android:maxWidth="75dp"
android:scaleType="center"
android:src="@drawable/ic_action_picture" >
<!-- android:background="@drawable/custom_button_blue" -->
</ImageButton>
<ImageButton
android:id="@+id/shutter_customized_camera"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="1dp"
android:layout_weight="0.3"
android:adjustViewBounds="true"
android:background="@drawable/custom_button_blue"
android:contentDescription="@string/add"
android:maxWidth="75dp"
android:scaleType="center"
android:src="@drawable/ic_action_camera" >
</ImageButton>
<ImageButton
android:id="@+id/video_customized_camera"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:adjustViewBounds="true"
android:background="@null"
android:contentDescription="@string/add"
android:maxWidth="75dp"
android:scaleType="center"
android:src="@drawable/ic_action_video" >
<!-- android:background="@drawable/custom_button_blue" -->
</ImageButton>
</LinearLayout>
<TextView
android:id="@+id/camera_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button_holder_customized_cam"
android:layout_alignParentRight="true"
android:padding="15dp"
android:text="@string/no_time"
android:textColor="@color/red"
android:textSize="20sp"
android:visibility="invisible" >
</TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
以下是我为HorizontalScrollView设置边距的方法:
myHorizontalLayout = (PictureHorizontalLayout) findViewById(R.id.mygallery);
// apply margin to horizontal scroll view to take into account height of status bar
TypedValue tv = new TypedValue();
int actionBarHeight = 0;
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
Log.d(TAG, "actionbarHeight before: " + actionBarHeight);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) myHorizontalLayout.getLayoutParams();
Log.d(TAG, "actionbarHeight after: " + actionBarHeight);
params.setMargins(0, actionBarHeight, 0, 0);
Log.d(TAG, "ADJUST MARGINS OF HORIZONTAL LAYOUT");
myHorizontalLayout.setLayoutParams(params);
}
Run Code Online (Sandbox Code Playgroud)
注意:我也尝试添加android:layout_marginTop="?attr/actionBarSize"到我的布局文件中的HorizontalScrollView,但这也不起作用(垂直偏移仍然不正确)
做你想做的最好的方法是在叠加模式下使用ActionBar .然后,您可以在视图中使用以下边距,以确保它不会隐藏在操作栏后面.
<!-- Support library compatibility -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1572 次 |
| 最近记录: |