繁体   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