java - LinearLayout設(shè)置background不顯示所設(shè)置的圖片
問(wèn)題描述
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' > <FrameLayoutandroid: 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'> <RelativeLayoutandroid:layout_width='match_parent'android:layout_height='100dp'android:orientation='vertical'android:layout_weight='0.29'><ImageView android: android:layout_width='50dp' android:layout_height='50dp' android:src='http://www.leifengta.com.cn/wenda/@drawable/logo_red' android:layout_centerVertical='true' android:layout_alignLeft='@+id/textView' android:layout_alignStart='@+id/textView' /><TextView android: 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.TextInputLayoutandroid:layout_marginLeft='25dp'android:layout_marginRight='20dp'android:layout_marginTop='35dp'android: android:layout_width='match_parent'android:layout_height='wrap_content'><EditText android: android:layout_width='match_parent' android:layout_height='match_parent' android:hint='用戶名' /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayoutandroid:layout_marginLeft='25dp'android:layout_marginRight='20dp'android: android:layout_width='match_parent'android:layout_height='wrap_content'><EditText android: android:layout_width='match_parent' android:layout_height='match_parent' android:hint='密碼' /> </android.support.design.widget.TextInputLayout> <Buttonandroid: 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' /> <TextViewandroid: 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='沒(méi)有賬號(hào)?注冊(cè)一個(gè)'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(); }
背景顯示為白色 很是糾結(jié)
問(wèn)題解答
回答1:我是有 三個(gè)文件夾 一個(gè)drawable drawable-v21 drawable-xxhdpi之前放在了drawable內(nèi) 背景圖片被 94kb的jpg 格式然后 放在drawable-xxhdpi 下 就可以成功顯示了
有沒(méi)有知道原因的
回答2:看了好幾遍沒(méi)發(fā)現(xiàn)什么端倪,而且拷到我的AS里面也沒(méi)發(fā)現(xiàn)大問(wèn)題,也只發(fā)現(xiàn)有屬性使用不當(dāng):
android:textSize='30dp'//字號(hào)建議用spandroid:layout_below='@id/button_login'//LinearLayout里面沒(méi)有l(wèi)ayout_below
個(gè)人懷疑可能是非布局因素造成的,因此有兩個(gè)問(wèn)題想確認(rèn)下:1、@drawable/background_login,是個(gè)什么資源,png之類的圖片還是xml文件?2、style.xml里面對(duì)theme的定義是怎樣的?
回答3:fragment使用肯定會(huì)用自己的根布局的圖片,你把背景寫到fragment_login_replace.xml這個(gè)文件不就好了
相關(guān)文章:
1. html5和Flash對(duì)抗是什么情況?2. html5 - datatables 加載不出來(lái)數(shù)據(jù)。3. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????4. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!5. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法6. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?7. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]8. javascript - QQ第三方登錄的問(wèn)題9. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。10. spring-mvc - spring-session-redis HttpSessionListener失效

網(wǎng)公網(wǎng)安備