簡體   English   中英

ListView背景

[英]ListView Background

編輯:

我在為ListView設置背景圖像時遇到問題。 在活動的圖形視圖中看起來不錯,但是在電話上根本沒有背景。 這是我的活動.xml代碼:

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

   <ListView
      android:id="@+id/listPlan"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:divider="@null"
      android:cacheColorHint="#00000000" 
      android:listSelector="@android:color/transparent" 
      android:scrollingCache="false" 
      android:dividerHeight="5dp" >

   </ListView>

</LinearLayout>

如果這對我的問題有所幫助,則它是GroupActivity中的一項活動。 我已經嘗試了一切-給android:background提供ListViewLinearLayout甚至父活動( GroupActivity ),更改android:layout值的所有項目,我無能為力。

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/text"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" 
     android:textSize="20sp"
     android:padding="15dp" 
     android:scrollHorizontally="true" >
</TextView>

這就是我的“單一列表項”的樣子,也許有一些錯誤?

我僅在編輯<TextView>並將其賦予android:background時才看到差異,彼此嘗試更改該列表視圖的背景是不存在的-例如,我將android:cacheColorHint="#00000000"更改為android:cacheColorHint="#FFFFFFFF" -什么也沒發生。

我將再嘗試一次-在將布局從“線性”更改為“相對”之后,什么也沒發生,但這(感謝@Sam)讓我思考。 也許我必須在AndroidManifest.xml中添加一些內容? 如果代碼工作正常,也許這個父級GroupActivityListView影響更大,那么我想。 不幸的是,我無法放置圖像,但是您可以在此處看到此ListView兩種狀態: https : //www.dropbox.com/sh/y5dgibei5uq9kv9/afeIvgW18g

哇,問題有點奇怪,因為當我嘗試為ListView設置android:textColor ,沒有任何改變! 這是我的styles.xml:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>

感謝您的每一個回應。

最后編輯!

好的,問題解決了,因為沒有任何幫助,我嘗試了另一種方法,只是在代碼中設置了ListView背景:

if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        list.setBackgroundResource(R.drawable.background);
    else list.setBackgroundResource(R.drawable.background_landscape);

現在一切正常! 謝謝大家的回應。 和平了。

這解決了我的問題:

android:cacheColorHint="#0000"

將其添加到您的列表視圖:

<ListView
android:id="@+id/listPlan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cacheColorHint="#0000">

“#0000”->透明顏色代碼

只需將其添加到listview.xml文件

android:cacheColorHint="#00000000"

或者您可以使用Expandable Listview
編輯:

使用Relative layout而不是linear layout ,請檢查../

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/ic_launcher" 
        android:cacheColorHint="#00000000">
    </ListView>

</RelativeLayout>

嘗試這個 :

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
     android:layout_height="match_parent"   
     android:orientation="vertical" >


      <ListView
       android:id="@+id/contract_diary_list"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"        
       android:fadingEdge="none"        
       android:divider="@null"
       android:scrollingCache="false"
      android:listSelector="@android:color/transparent"
     >
     </ListView> 

   </LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM