development

Android : BOTTOM의 탭

big-blog 2020. 6. 13. 09:27
반응형

Android : BOTTOM의 탭


나는 이것에 대해 약간의 대화를 보았지만 명확한 것은 없습니다. TabWidget의 탭을 화면 하단에 배치하는 방법이 있습니까? 그렇다면 어떻게?

다음을 시도했지만 작동하지 않았습니다.

a) 프레임 레이아웃 아래의 탭 위젯
설정 b) 탭 위젯의 중력을 "아래"로 설정

감사! llappall


화면 하단에 탭을 표시하는 가장 간단하고 강력하며 확장 가능한 솔루션입니다.

  1. 수직 LinearLayout에서 FrameLayout을 TabWidget 위에 놓습니다.
  2. 설정 layout_heightwrap_contentFrameLayout이와 TabWidget 모두
  3. FrameLayout의 설정 android:layout_weight="1"
  4. TabWidget 설정 android:layout_weight="0"(0은 기본값이지만 강조, 가독성 등)
  5. TabWidget을 설정하십시오 android:layout_marginBottom="-4dp"(하단 분배기를 제거하기 위해)

전체 코드 :

<?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="5dp">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_weight="1"/>

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

    </LinearLayout>

</TabHost>

시도해보십시오.) 스크롤 할 때 처리 방법을 모르기 때문에 FrameLayout (@ id / tabcontent)의 내용을 봅니다. 내 경우에는 ListView를 탭의 내용으로 사용했기 때문에 작동합니다. . :) 그것이 도움이되기를 바랍니다.

<?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">
    <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
        <FrameLayout android:id="@android:id/tabcontent"
             android:layout_width="fill_parent" 
             android:layout_height="fill_parent"
             android:layout_alignParentTop="true" 
             android:layout_above="@android:id/tabs" />
    <TabWidget android:id="@android:id/tabs"
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true" />
    </RelativeLayout>
</TabHost>

줄을 제거하는 방법이 있습니다.

1)이 튜토리얼을 따르십시오 : android-tabs-with-fragments

2) 그런 다음 Leaudro가 위에서 제안한 RelativeLayout 변경 사항을 적용하십시오 (레이아웃 소품을 모든 FrameLayouts에 적용하십시오).

항목 # 1의 tab.xml에 ImageView를 추가하고 탭과 같은 모양의 iPhone을 얻을 수도 있습니다.

여기 내가 지금하고있는 일의 스크린 샷이 있습니다. 나는 여전히 아이콘을 선택하고 수평 분포를 동일하게 유지하기 위해 할 일이 있지만 아이디어를 얻습니다. 필자의 경우 조각을 사용하고 있지만 동일한 주체가 표준 탭보기에 적용되어야합니다.

enter image description here


Not sure if it will work for all versions of Android (especially those with custom UI stuff), but I was able to remove the gray bar at the bottom by adding

 android:layout_marginBottom="-3dp"

to the TabWidget XML...


For all those of you that try to remove the separating line of the tabWidget, here is an example project (and its respective tutorial), that work great for customizing the tabs and thus removing problems when tabs are at bottom. Eclipse Project: android-custom-tabs ; Original explanation: blog; Hope this helped.


There are two ways to display tabs at the bottom of a tab activity.

  1. Using relative layout
  2. Using Layout_weight attribute

Please check the link for more details.


<?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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:background="#252a31"
            android:tabStripEnabled="false" >
        </TabWidget>
    </LinearLayout>

</TabHost>

This may not be exactly what you're looking for (it's not an "easy" solution to send your Tabs to the bottom of the screen) but is nevertheless an interesting alternative solution I would like to flag to you :

ScrollableTabHost is designed to behave like TabHost, but with an additional scrollview to fit more items ...

maybe digging into this open-source project you'll find an answer to your question. If I see anything easier I'll come back to you.


I was having the same problem with android tabs when trying to place them on the bottom of the screen. My scenario was to not use a layout file and create the tabs in code, I was also looking to fire activities from each tab which seemed a bit too complex using other approaches so, here is the sample code to overcome the problem:

adding-tabs-in-android-and-placing-them


Yes, see: link, but he used xml layouts, not activities to create new tab, so put his xml code (set paddingTop for FrameLayout - 0px) and then write the code:

public class SomeActivity extends ActivityGroup {

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

    TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host); 

    tab_host.setup(this.getLocalActivityManager());

    TabSpec ts1 = tab_host.newTabSpec("TAB_DATE"); 
    ts1.setIndicator("tab1"); 
    ts1.setContent(new Intent(this, Registration.class)); 
    tab_host.addTab(ts1); 

    TabSpec ts2 = tab_host.newTabSpec("TAB_GEO"); 
    ts2.setIndicator("tab2"); 
    ts2.setContent(new Intent(this, Login.class)); 
    tab_host.addTab(ts2); 

    TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT"); 
    ts3.setIndicator("tab3"); 
    ts3.setContent(new Intent(this, Registration.class)); 
    tab_host.addTab(ts3); 

    tab_host.setCurrentTab(0);      


}

}


I recomend use this code for stable work, it optimized for nested fragments in tab (for example nested MapFragment) and tested on "do not keep activities": https://stackoverflow.com/a/23150258/2765497

참고URL : https://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom

반응형