2015-11-27 2 views
0

Ниже файл макета:Android TabHost не показывая

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="hk.teawood.httpwww.t_factory.stock_list" 
    android:id="@android:id/tabhost"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"></TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <LinearLayout 
        android:id="@+id/linearLayout" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"></LinearLayout> 

       <LinearLayout 
        android:id="@+id/linearLayout2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"></LinearLayout> 

       <LinearLayout 
        android:id="@+id/linearLayout3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"></LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 

</TabHost> 

А вот файл Java

import android.app.TabActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ListView; 
import android.widget.Toast; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.util.ArrayList; 

public class stock_list extends TabActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_stock_list); 

     //iniControls(); 

     //loadList(); 
    } 
} 

Я просто поставить TabHost в макет, который ожидаемый макет должен быть что-то вроде этого : enter image description here

Но результат был, пустая активность показана: enter image description here

Как исправить эту проблему?

+0

Если это точный код, который вы работаете, то все ваши взгляды пусты и прозрачны. –

+0

@MikeM. Тогда как я могу сделать представление непрозрачным? Я пытаюсь добавить вкладки к действию – User2012384

+1

Ну, во-первых, если вы хотите, чтобы LinearLayouts были вашими вкладками, они должны быть внутри тегов ''. Кроме того, LinearLayouts по умолчанию прозрачны. Если вам нужны цвета, укажите атрибут 'background' для каждого. –

ответ

0

Я последовал за этот пост:

https://gist.github.com/jerolimov/618086

и изменил код немного:

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="hk.teawood.httpwww.t_factory.stock_list"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:tag="tab0" 
       android:text="Lend Items" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:tag="tab0" 
       android:text="Free Items" /> 
     </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 


      <ListView 
       android:id="@+id/ListViewId2" 
       android:layout_width="366dp" 
       android:layout_height="match_parent" /> 
      <ListView 
       android:id="@+id/ListViewId" 
       android:layout_width="366dp" 
       android:layout_height="match_parent" /> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

И теперь он работает!

enter image description here