java - LinearLayout setting background does not display the set image
过去多啦不再A梦
过去多啦不再A梦 2017-05-27 17:40:27
0
3
638

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();
    }

The background is displayed in white, which is very confusing

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
漂亮男人

I have three folders, one drawable drawable-v21 drawable-xxhdpi
I put it in drawable before. The background image is in 94kb jpg format
Then I put it under drawable-xxhdpi and it can be displayed successfully

Does anyone know the reason

習慣沉默

I looked at it several times and found no clues, and I didn’t find any big problems when I copied it to my AS. I only found that some attributes were used improperly:

android:textSize="30dp"//字号建议用sp
android:layout_below="@id/button_login"//LinearLayout里面没有layout_below

I personally suspect that it may be caused by non-layout factors, so I have two questions to confirm:
1. @drawable/background_login, what kind of resource is it, a picture like png or an xml file?
2. What is the definition of theme in style.xml?

过去多啦不再A梦

When using a fragment, it will definitely use its own root layout image. Just write the background to the fragment_login_replace.xml file.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!