2013-10-13 84 views
0

我想在整个屏幕上填充自定义视图。我用重量,但仍然不工作。 我正在使用以下代码。请有人告诉我解决方案。自定义视图不能填满整个屏幕

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/LinearLayout2" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/back" 
android:orientation="horizontal" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<com.alarm_animation.CustomeView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="#ffffff" /> 

回答

1

使用match_parent不WRAP_CONTENT上的自定义视图。

删除layout_weight。在这种情况下不需要。

+0

我已经尝试过了它不工作,但它仍然四面 –

+0

留下空格,则你也应该删除你的线性布局的填充。 – Kuffs

+0

感谢它工作:)请你能详细说明它是如何工作的? –

0

尝试建立自定义视图像this.-

<com.alarm_animation.CustomeView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" /> 
0

影响你的布局文件这样

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/back" 
    tools:context=".MainActivity" > 

    <com.alarm_animation.CustomeView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#ffffff" /> 
+0

我对此有所了解,但它仍然不能正常工作输出 –

+0

也许您的自定义视图不能很好地缩放。但是,这是你可以在XML布局 – JWqvist

+0

您是否删除了线性布局的边距? – JWqvist