java - LinearLayout设置background不显示所设置的图片

查看:70
本文介绍了java - LinearLayout设置background不显示所设置的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_login"
    >

    <FrameLayout
        android:id="@+id/fragment_login_replace"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

xml=====>fragment_login_replace

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/background_login"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="vertical"
        android:layout_weight="0.29">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/logo_red"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/textView"
            android:layout_alignStart="@+id/textView" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="219dp"
            android:layout_height="wrap_content"
            android:textSize="30dp"
            android:text="Home Work"
            android:textAllCaps="false"
            android:textColor="#ffff"
            android:textStyle="bold"
            android:layout_marginLeft="31dp"
            android:layout_marginStart="31dp"
            android:layout_below="@+id/imageView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

    </RelativeLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_marginLeft="25dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="35dp"
        android:id="@+id/textinput_login_username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/edit_login_username"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="用户名" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_marginLeft="25dp"
        android:layout_marginRight="20dp"
        android:id="@+id/textinput_login_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/edit_login_password"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="密码" />
    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/button_login"
        android:layout_width="287dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="43dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:background="@color/colorPrimary"
        android:text="登录"
        android:textColor="@color/white" />

    <TextView
        android:id="@+id/text_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button_login"
        android:layout_marginTop="10dp"
        android:layout_weight="0.03"
        android:gravity="center_horizontal"
        android:text="没有账号?注册一个"
        android:textColor="@color/colorPrimary"
        android:textSize="15sp" />

</LinearLayout>

Activity

    public void init(LoginFragment fragment){
        FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment_login_replace, fragment, "login");
        transaction.commit();
    }

背景显示为白色 很是纠结

解决方案

我是有 三个文件夹 一个drawable drawable-v21 drawable-xxhdpi
之前放在了drawable内 背景图片被 94kb的jpg 格式
然后 放在drawable-xxhdpi 下 就可以成功显示了

有没有知道原因的

这篇关于java - LinearLayout设置background不显示所设置的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆