【问题标题】:Add a footerview to a Tab host Android将页脚视图添加到 Tab 主机 Android
【发布时间】:2013-07-26 08:57:13
【问题描述】:

我想添加一个页脚视图,一个列表视图中加载的元素的计数器。我想知道我应该把页脚视图放在哪里。我的列表视图中已经有一个,我想我不能把它放在那里,因为我希望它一直可见,而不是像我拥有的​​那样深入到它的底部。

代码:

列表视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical">

<ListView
    android:id="@+id/lista"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stackFromBottom="false"
    android:transcriptMode="normal"
    />
</LinearLayout>

标签代码:

<RelativeLayout 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: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=".MainTabActivity" >
<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >
    <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"
            android:gravity="center_vertical|fill_vertical|fill_horizontal" >
        </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/lista"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:stackFromBottom="false"
                    android:transcriptMode="normal"
                    />
            </LinearLayout>
            <LinearLayout
                android:id="b"
            </LinearLayout>

            <LinearLayout
                android:id="c"
            </LinearLayout>                
            <LinearLayout
                android:id="d"
            </LinearLayout>                            
        </FrameLayout>
    </LinearLayout>                      
</TabHost>     

我有这个:http://imageshack.us/photo/my-images/23/6a3t.jpg/

我想要这个:http://imageshack.us/photo/my-images/809/kesm.jpg/

【问题讨论】:

    标签: android android-listview android-tabhost footer


    【解决方案1】:

    如果将具有 match_parent 宽度和高度的 FrameLayout 放在 LinearLayout 中,所有内容都将隐藏在屏幕之外。

    有两种形式可以添加页脚:

    首先,使用以下尺寸设置框架布局:

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

    第二,使用RelativeLayout并将所有内容设置在其他内容下方,如果您想在内容上方添加页脚,则使用layout_alignParentBottom = true添加页脚,如果您希望页脚与内容一起添加,请在最后一个视图下方添加页脚。

    【讨论】:

      【解决方案2】:

      ListView.addFooterView怎么样?

      来自文档:

      添加一个固定视图以显示在列表底部。如果添加FooterView 被多次调用,视图将按照它们出现的顺序出现 添加。使用此调用添加的视图可以根据需要获得焦点。

      注意:在调用 setAdapter 之前调用它。这样 ListView 可以 将提供的光标用一个也将解释标题的光标包装起来 和页脚视图。

      【讨论】:

      • 我已经为列表视图设置了页脚视图,此外,该解决方案无法满足我的需要
      【解决方案3】:

      也许这可以帮助你。

      创建一个名为footer.xml 的文件 并将此代码添加到其中

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="40dp"
          android:layout_gravity="bottom"
          android:gravity="bottom"
       android:layout_weight=".15"
          android:orientation="horizontal"
          android:background="@drawable/bckkaup" >
          <ImageView
              android:id="@+id/lborder"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight=".14"
              android:background="@drawable/action_bar_left_button"
              android:src="@drawable/over_9"
              android:scaleType="fitXY" />
          <ImageView
              android:id="@+id/unknown"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight=".14"
              android:background="@drawable/action_bar_left_button"
              android:src="@drawable/cartoon_9"
              android:scaleType="fitXY" />
      
          <ImageView
              android:id="@+id/open"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight=".14"
              android:background="@drawable/action_bar_left_button"
              android:src="@drawable/gallery_9"
              android:scaleType="fitXY"
              android:hapticFeedbackEnabled="true"
              android:soundEffectsEnabled="true"
      
              />
      
          <View
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.03" 
              android:src="@drawable/action_bar_right_button"
              android:background="@drawable/action_bar_left_button"
              />
      
          <ImageView
              android:id="@+id/opencam"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight=".14"
              android:background="@drawable/action_bar_left_button"
              android:src="@drawable/camera_9"
              android:scaleType="fitXY"
              android:hapticFeedbackEnabled="true"
              android:soundEffectsEnabled="true"
              />
          <ImageView
              android:id="@+id/color"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight=".14"
              android:background="@drawable/action_bar_left_button"
              android:src="@drawable/stylish_9"
              android:scaleType="fitXY" />
              <ImageView
              android:id="@+id/rborder"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:background="@drawable/action_bar_left_button"
              android:src="@drawable/frame_9"
              android:layout_weight=".14" 
              android:scaleType="fitXY"/>
      
      
      </LinearLayout>
      

      然后在你的main layout 添加此代码

       <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="40dp"
          android:id="@+id/down"
          android:layout_alignParentBottom="true" >
      
          <include
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              layout="@layout/footer" >
      
          </include>
      </LinearLayout>    
      

      这会给你一个页脚。您也可以更改重力以使其成为标题。 我知道你要的是标签,但我想我应该和你分享一下,也许它对你有好处。

      【讨论】:

        猜你喜欢
        • 2015-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-09
        • 2016-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多