java - LinearLayout設定background不顯示所設定的圖片
过去多啦不再A梦
过去多啦不再A梦 2017-05-27 17:40:27
0
3
639

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

背景顯示為白色 很是糾結

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

全部回覆(3)
漂亮男人

我有 三個資料夾 一個drawable drawable-v21 drawable-xxhdpi
之前放在了drawable內 背景圖片被 94kb的jpg 格式
然後 放在drawable-xxhdpi 下 就可以成功顯示了

有沒有知道原因的

習慣沉默

看了好幾遍沒發現什麼端倪,而且拷到我的AS裡面也沒發現大問題,也只發現有屬性使用不當:

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

個人懷疑可能是非版面因素造成的,因此有兩個問題想確認下:
1、@drawable/background_login,是個什麼資源,png之類的圖片還是xml檔?
2、style.xml裡面對theme的定義是怎麼樣的?

过去多啦不再A梦

fragment使用肯定會用自己的根佈局的圖片,你把背景寫到fragment_login_replace.xml這個文件不就好了

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!