2

Linerlayout將不適合在全屏幕的白色背景色顯示.. 任何想法使兩側適合全屏?relativelayout內的線性佈局不完美的全屏適合

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"\> 
<Button 
android:id="@+id/bClose" 
android:layout_width="40dp" 
android:layout_height="40dp" 
android:layout_alignParentRight="true" 
android:layout_margin="0dp" 
android:background="@drawable/round_button_background" 
android:gravity="center_vertical|center_horizontal" 
android:onClick="cancelActivity" 
android:text="@string/x_close" 
android:textColor="#FFF" 
android:textSize="15sp" 
android:textStyle="bold" 
android:layout_alignParentTop="true" 
/> 


<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
android:fillViewport="true" 
android:gravity="center_vertical|center_horizontal" 
android:id="@+id/preview_frag" 
android:focusable="true"> 
<requestFocus /> 
</LinearLayout> 
</RelativeLayout> 

enter image description here

回答

1

你可以嘗試使用webview嗎?通過它實現填充和保證金調整的WebView ....使用 - (負)值

+2

對您有幫助嗎? – sugansoft

+1

非常感謝你...ü保存我的時間..它的工作正常。 – Moorthy

0

這工作完全正常。嘗試使用match_parent而不是fill_parent。 檢查圖像是否有空白。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <Button 
     android:id="@+id/bClose" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_margin="0dp" 
     android:background="@drawable/ic_event_white_24dp" 
     android:gravity="center_vertical|center_horizontal" 
     android:text="close" 
     android:textColor="#FFF" 
     android:textSize="15sp" 
     android:textStyle="bold" /> 


    <LinearLayout 
     android:id="@+id/preview_frag" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true" 
     android:focusable="true" 
     android:background="@color/theme_primary" 
     android:gravity="center_vertical|center_horizontal" 
     android:orientation="horizontal"> 

     <requestFocus /> 
    </LinearLayout> 
</RelativeLayout 
0

佈局是正確的,可能是問題的片段佈局,因爲你LinearLayout似乎是一個片段容器。 檢查您的fragment_layout是否有一些邊距或填充。 另外,作爲一個建議,你應該從fill_parent改變match_parent

+0

謝謝你的回覆...確定試試這個代碼...你可以詳細解釋一下... – Moorthy

+0

你的'LinearLayout'有'android:id =「@ + id/preview_frag 「'所以我假定你使用這個佈局作爲一個片段容器,檢查你在這裏添加/替換的片段的佈局,也許問題出現在這個fr例如邊緣/填充,錯誤的重力... –

+0

非常感謝你萊昂納多...我會chk我的代碼... – Moorthy

0

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <Button 
     android:id="@+id/bClose" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignParentRight="true" 
     android:layout_margin="0dp" 
     android:background="@drawable/round_button_background" 
     android:gravity="center_vertical|center_horizontal" 
     android:onClick="cancelActivity" 
     android:text="@string/x_close" 
     android:textColor="#FFF" 
     android:textSize="15sp" 
     android:textStyle="bold" 
     android:layout_alignParentTop="true" 
     /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:fillViewport="true" 
     android:gravity="center_vertical|center_horizontal" 
     android:id="@+id/preview_frag" 
     android:focusable="true"> 
     <requestFocus /> 
    </LinearLayout> 
</RelativeLayout> 
0

如果你正在尋找對LinearLayout頂部的關閉按鈕,你可以嘗試使用父視圖FrameLayout,像這樣: -

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/frameLayout1"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/linearLayout1" 
     android:background="@android:color/holo_blue_bright" /> 
    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button1" 
     android:layout_gravity="right" /> 
</FrameLayout> 

輸出將類似下面: - enter image description here

0

替換高度和寬度屬性FILL_PARENT到match_parent從LinearLayout中去除重力試試上面的代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<Button 
android:id="@+id/bClose" 
android:layout_width="40dp" 
android:layout_height="40dp" 
android:layout_alignParentRight="true" 
android:layout_margin="0dp" 
android:background="@drawable/round_button_background" 
android:gravity="center_vertical|center_horizontal" 
android:onClick="cancelActivity" 
android:text="@string/x_close" 
android:textColor="#FFF" 
android:textSize="15sp" 
android:textStyle="bold" 
android:layout_alignParentTop="true" 
/> 


<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:id="@+id/preview_frag"> 
</LinearLayout> 
</RelativeLayout> 
+0

感謝您的答覆..但此代碼同樣的問題發生 – Moorthy

+0

然後肯定這些白色空間來自其他鏈接的佈局共享佈局,在你的線性佈局調用 – Omi

+0

我不明白...你可以詳細解釋一下 – Moorthy

0

如果你正在使用的ImageView嘗試使用試試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<Button 
    android:id="@+id/bClose" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_margin="0dp" 
    android:background="@drawable/blockclose" 
    android:gravity="center_vertical|center_horizontal" 
    android:onClick="cancelActivity" 
    android:text="x_close" 
    android:textColor="#FFF" 
    android:textSize="15sp" 
    android:textStyle="bold" /> 


<LinearLayout 
    android:id="@+id/preview_frag" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:background="@drawable/bg" 
    android:focusable="true" 
    android:gravity="center_vertical|center_horizontal" 
    android:orientation="horizontal"> 


    <requestFocus /> 
</LinearLayout> 
</RelativeLayout> 

android:scaleType="fitXY"

-1

我也面臨同樣的問題,給予負邊距值其工作正常,我 示例代碼

<body style='margin:-0.5px;'> 

我希望上面的代碼會適合你

+0

亞我也得到了輸出:)不錯 – sugansoft

+1

謝謝你的回覆....雅這個代碼工作正常... – Moorthy