2014-01-09 4 views
0

Я стараюсь DESIN экран, который представляет собой макет фрагмента, как этотПоместите лабиринт внутри фрагмента?

https://dl.dropboxusercontent.com/u/37599516/Untitled.png

Или, как это в Instagram

https://dl.dropboxusercontent.com/u/37599516/Screenshot%202014-01-09%2010.27.19.png

я попробовать этот код:

<LinearLayout 
    android:id="@+id/thumbnail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/relativeLayout1" 
    android:layout_marginRight="5dip" 
    android:background="@drawable/image_bg" 
    android:padding="3dip" > 

    <ImageView 
     android:id="@+id/userAvatar" 
     android:layout_width="wrap_content" 
     android:layout_height="89dp" 
     android:src="@drawable/test_avatar" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/thumbnail" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/thumbnail" 
    android:layout_below="@+id/relativeLayout1" 
    android:layout_toRightOf="@+id/thumbnail" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="soloco bolo" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/ImageView01" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:src="@drawable/description_section_icon" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:gravity="center_vertical" 
      android:text="123456" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:src="@drawable/ic_menu_add" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button1" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="123dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="125dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </LinearLayout> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/thumbnail" > 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="center_vertical|center_horizontal" 
     android:text="Đà Nẵng" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

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

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="match_parent" 
      android:layout_height="68dp" 
      android:gravity="center_horizontal|center_vertical" 
      android:text="Activate" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_horizontal|center_vertical" 
      android:text="6/1/2013-7/1/2013" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 
    </LinearLayout> 
</LinearLayout> 
<LinearLayout 
    android:id="@+id/containerTabhost" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/relativeLayout2" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/linearLayout1" 
    android:background="@drawable/backgroundactionbar" 
    android:orientation="vertical" > 
    <TabHost 
     android:id="@+id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1.30" > 

     <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="92dp" > 
      </TabWidget> 

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

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

        <ListView 
         android:id="@+id/tab1list_place_list" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:divider="#b5b5b5" 
         android:dividerHeight="1dp" 
         android:listSelector="@drawable/list_selector" > 
        </ListView> 
       </LinearLayout> 

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

        <ListView 
         android:id="@+id/tab2list_place_list" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:divider="#b5b5b5" 
         android:dividerHeight="1dp" 
         android:listSelector="@drawable/list_selector" /> 
       </LinearLayout> 

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

        <ListView 
         android:id="@+id/tab3list_place_list" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:divider="#b5b5b5" 
         android:dividerHeight="1dp" 
         android:listSelector="@drawable/list_selector" /> 
       </LinearLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 

и используя этот код для работы с хостом вкладки в моем классе фрагментов

public class HostFragment extends Fragment { 
private FragmentTabHost mTabHost; 

public HostFragment() { 
    // Empty constructor required for fragment subclasses 
} 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_host_layout, 
      container, false); 

    setHasOptionsMenu(true); 
    TabHost mTabHost = (TabHost) rootView.findViewById(R.id.tabhost); 

     mTabHost.setup(); 
    TabSpec photospec = mTabHost.newTabSpec("Search"); 
    photospec.setIndicator("Search", 
    getResources().getDrawable(R.drawable.action_search)); 
    Intent searchIntent = new Intent(getActivity(), 
    HostViewIntroduce.class); 
    photospec.setContent(searchIntent); 

    TabSpec songspec = mTabHost.newTabSpec("Favorites"); 
    songspec.setIndicator("Favorites", 
    getResources().getDrawable(R.drawable.action_search)); 
    Intent favoriteIntent = new Intent(getActivity(), 
    HostViewTips.class); 
    songspec.setContent(favoriteIntent); 

mTabHost.addTab(songspec); 
mTabHost.addTab(photospec); 

    return rootView; 

} 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

} 


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // TODO Auto-generated method stub 
    return super.onOptionsItemSelected(item); 
} 

} 

и бросить NullPointer за исключением

01-09 13:40:31.781: E/AndroidRuntime(5871): FATAL EXCEPTION: main 
01-09 13:40:31.781: E/AndroidRuntime(5871): java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'? 
+0

Цитирование собственное сообщение об ошибке: 'Вы забыли назвать 'общественного недействительными установки (LocalActivityManager activityGroup)'' – WarrenFaith

+0

Проверьте это HTTP: // StackOverflow .com/questions/18120510/dynamic-change-the-fragments-inside-a-fragment-tab-host/19859871 # 19859871 – AndroidHacker

+0

@WarrenFaith Я понятия не имею, что это за вопрос. Я пытаюсь это сделать, но я не могу найти ничего, чтобы решить мою проблему. – ajkala

ответ

1

Вы должны использовать FragmentTabHost «s пользовательские addTab(), который также будет принимать ваш класс Fragment в качестве параметра.

Заменить

TabSpec photospec = mTabHost.newTabSpec("Search"); 
photospec.setIndicator("Search", 
getResources().getDrawable(R.drawable.action_search)); 
Intent searchIntent = new Intent(getActivity(), 
HostViewIntroduce.class); 
photospec.setContent(searchIntent); 

TabSpec songspec = mTabHost.newTabSpec("Favorites"); 
songspec.setIndicator("Favorites", 
getResources().getDrawable(R.drawable.action_search)); 
Intent favoriteIntent = new Intent(getActivity(), 
HostViewTips.class); 
songspec.setContent(favoriteIntent); 

с

TabHost.TabSpec photospec = mTabHost.newTabSpec("Search"); 
    photospec.setIndicator("Search", 
    getResources().getDrawable(R.drawable.action_search)); 
    photospec.setIndicator(rootView); 
    mTabHost.addTab(photospec, HostViewIntroduce.class, null); 


    TabSpec songspec = mTabHost.newTabSpec("Favorites"); 
    songspec.setIndicator("Favorites", 
    getResources().getDrawable(R.drawable.action_search)); 
    songspec.setIndicator(rootView); 
    mTabHost.addTab(songspec, HostViewTips.class, null); 
+0

Я не получаю ваш ответ. Так что мне нужно написать собственный собственный класс FragmentTabHost, так? – ajkala

+0

Нет, вам нужно просто использовать это в своем ** HostFragment ** – Piyush

+0

Я заменяю arcoding на yor answer, но в addTab() есть ошибка: метод addTab (TabHost.TabSpec) в типе TabHost не применим для аргументов (TabHost.TabSpec, Class , null) – ajkala

Смежные вопросы