Maison  >  Questions et réponses  >  le corps du texte

java - L'arrière-plan du paramètre LinearLayout n'affiche pas l'image définie

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>

Activité

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

L'arrière-plan est affiché en blanc, ce qui prête à confusion

过去多啦不再A梦过去多啦不再A梦2702 Il y a quelques jours633

répondre à tous(3)je répondrai

  • 漂亮男人

    漂亮男人2017-05-27 17:42:27

    J'ai trois dossiers, un drawable drawable-v21 drawable-xxhdpi
    L'image de fond qui était précédemment placée dans le drawable est au format jpg de 94 Ko
    puis placée sous drawable-xxhdpi, elle peut être affiché avec succès了

    Est-ce que quelqu'un connaît la raison

    répondre
    0
  • 習慣沉默

    習慣沉默2017-05-27 17:42:27

    Je l'ai regardé plusieurs fois et je n'ai trouvé aucun indice, et je n'ai trouvé aucun gros problème lorsque je l'ai copié sur mon AS, j'ai seulement constaté que certains attributs étaient mal utilisés :

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

    Personnellement, je soupçonne que cela peut être dû à des facteurs non liés à la mise en page, j'ai donc deux questions à confirmer :
    1 @drawable/background_login, de quel type de ressource s'agit-il, une image comme un png ou un fichier XML ?
    2. Quelle est la définition du thème dans style.xml ?

    répondre
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-27 17:42:27

    fragment utilisera certainement sa propre image de mise en page racine, écrivez simplement l'arrière-plan dans le fichier fragment_login_replace.xml

    répondre
    0
  • Annulerrépondre