自定义视图不会填满整个屏幕

时间:2013-10-13 09:30:39

标签: android android-layout

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

<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" />

3 个答案:

答案 0 :(得分:1)

在自定义视图中使用match_parent而不是wrap_content。

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

答案 1 :(得分:0)

尝试像这样设置自定义视图.-

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

答案 2 :(得分: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" />
相关问题