2016-07-29 65 views
1

我的佈局與居中圖片視圖屏幕高度取決於主題

<?xml version="1.0" encoding="utf-8"?> 
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/WHITE"> 

    <ImageView 
     android:id="@+id/powered_by" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:src="@drawable/powered_by" /> 

    <ImageView 
     android:id="@+id/splash_logo" 
     android:src="@drawable/logo" 
     app:layout_widthPercent="70%" 
     app:layout_heightPercent="70%" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:adjustViewBounds="true" 
     android:visibility="invisible" /> 

</android.support.percent.PercentRelativeLayout> 

這裏是主題設置爲我的活動

<style name="SplashTheme" parent="android:Theme.Holo.Light"> 
    <item name="android:windowBackground">@drawable/splash</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
</style> 

當我改變父主題android:Theme.DeviceDefault.LightImageView的出現有點偏高,而不是在屏幕的中心。似乎我的設備的父視圖現在不是從屏幕底部開始,而是從底部工具欄開始(我使用帶屏幕按鈕的Nexus 5X)。

我想爲現代對話框外觀使用設備默認主題,但我也需要在所有設備上精確地顯示此圖像視圖。

怎麼辦?

回答

0

看起來好像android:Theme.DeviceDefault.Light沒有設置android:windowFullScreen。因此,您需要與家長android:Theme.DeviceDefault.Light一起創建自己的主題並更改要更改的項目的值

<style name="TestTheme" parent="android:Theme.DeviceDefault.Light"> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
</style> 
+0

不幸的是,它對我不起作用。我使用了相同的樣式,圖像視圖不以此爲中心。 –

+0

需要發佈佈局代碼,然後查看問題是否存在 – ganlaw