首页 文章

Android中的ListView透明度

提问于
浏览
0

我已经设置了四个选项卡,每个选项卡都有一个listview,我在listview java文件中添加了代码以使列表透明,但是,我有一个半透明的灰色框覆盖75%的屏幕,我无法弄清楚为什么,我有我的其他列表视图的背景,他们是完全透明的,但tabhost中的列表有灰色框 .

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
    android:orientation="vertical"
   android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="2dp">
   <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="3dp"
        android:layout_weight="1"/>

    <TabWidget
        android:id="@android:id/tabs"
       android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"/>

</LinearLayout>
</TabHost>
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class Tabs extends TabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Draw
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Reusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, prem.class);

        // Initialise a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Prem").setIndicator("Prem",
                          res.getDrawable(R.drawable.icontabs))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, champ.class);

        // Initialise a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Champ").setIndicator("Champ",
                          res.getDrawable(R.drawable.champ))
                      .setContent(intent);
        tabHost.addTab(spec);


        // Do the same for the other tabs
        intent = new Intent().setClass(this, l1.class);
        spec = tabHost.newTabSpec("League 1").setIndicator("L",
                          res.getDrawable(R.drawable.l1))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, ll2.class);
        spec = tabHost.newTabSpec("l2").setIndicator("Le",
                          res.getDrawable(R.drawable.l2))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);
    }
}

public class l1 extends ListActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // Create an array of Strings, that will be put to our ListActivity
        String[] names = new String[] {"Le"};
        ListView lv = getListView();  
        lv.setBackgroundResource(R.drawable.le2);
        lv.setCacheColorHint(00000000); 
        this.setListAdapter(new ArrayAdapter<String>(this,
                R.layout.list_item, names));
    }

    // Get the item that was clicked
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
          if (position == 0) {

1 回答

  • 0

    在布局XML文件中,选项卡内容( FrameLayout )应位于选项卡窗口小部件之后,而不是之前 . 它's possible the box you are seeing is the tab widget'的背景 .

    像这样:

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </LinearLayout>
    </TabHost>
    

相关问题