根据固定页脚限制片段大小

时间:2014-09-08 08:42:00

标签: android android-layout android-fragments android-actionbar

demo design

我正在创建一个具有上述设计的Android应用程序。我已经创建了一个自定义操作栏并将其粘贴到我的MainActivity中的onCreateOptionsMenu。

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.action_bar);

我还在MainActivity中创建了一个固定的页脚,它基本上是用于在应用程序中触发不同片段的图像视图。现在,这些图像视图被设置为wrap_content的高度。

我的问题是 -

  1. 如何限制碎片的大小,使其粘在底部的固定视图组中,因为它没有特定的高度?
  2. 这是实现这种设计的最佳方法吗?在片段之间有固定的页脚交换?
  3. 如何创建和添加可重复使用的UI组件,类似于谷歌卡,我可以从服务器推送数据,并在滚动视图中动态包含这些数据。
  4. 谢谢。

    修改1

    activity_main -

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="dd.MainActivity" >
    
            <!-- Footer aligned to bottom -->
            <LinearLayout
                android:id="@+id/llFooterPlaceholder"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="vertical" >
    
                <View
                    android:layout_width="fill_parent"
                    android:layout_height="3dp"
                    android:background="@color/green" />
    
                <LinearLayout
                    android:id="@+id/llFooterMenu"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/bottom_bar"
                    android:orientation="horizontal" >
    
                    <ImageView
                        android:id="@+id/iv1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="20"
                        android:scaleType="fitCenter"
                        android:src="@drawable/state_definition_iv1" />
    
                    <ImageView
                        android:id="@+id/iv2"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="20"
                        android:scaleType="fitCenter"
                        android:src="@drawable/state_definition_iv2" />
    
                    <ImageView
                        android:id="@+id/iv3"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="20"
                        android:background="@color/green"
                        android:scaleType="center"
                        android:src="@drawable/state_definition_iv3" />
    
                    <ImageView
                        android:id="@+id/iv4"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="20"
                        android:scaleType="fitCenter"
                        android:src="@drawable/state_definition_iv4" />
    
                    <ImageView
                        android:id="@+id/iv5"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="20"
                        android:scaleType="fitCenter"
                        android:src="@drawable/state_definition_iv5" />
                </LinearLayout>
            </LinearLayout>
    
            <!-- Scrollable item above footer -->
            <ScrollView
                android:id="@+id/svContent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@id/llFooterPlaceholder"
                android:layout_alignParentTop="true" >
    
                <!-- Inflate the contents of the ScrollView dynamicaly -->
            </ScrollView>
    </RelativeLayout>
    

    fragment1在页脚的iv1上点击激活(布局尚未完成) -

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="30"
            android:background="#444"
            android:orientation="horizontal"
            android:padding="@dimen/item_padding" >
    
            <ImageView
                android:id="@+id/ivAvtar"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="30"
                android:background="#000"
                android:scaleType="fitCenter" />
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="50"
                android:background="#fff"
                android:orientation="vertical" >
    
                <TextView
                    android:id="@+id/tvUsername"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="50"
                    android:background="#0ff"
                    android:text="Username"
                    android:textColor="@color/green"
                    android:textStyle="bold" />
    
                <TextView
                    android:id="@+id/tvImageTitle"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="50"
                    android:background="#ff0"
                    android:text="Title"
                    android:textColor="@color/orange"
                    android:textStyle="italic" />
            </LinearLayout>
    
            <TextView
                android:id="@+id/tvTimestamp"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="20"
                android:gravity="center"
                android:text="Timestamp"
                android:textColor="@color/green"
                android:textStyle="bold" />
        </LinearLayout>
    
        <ImageView
            android:id="@+id/ivImage"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="60"
            android:background="#999"
            android:padding="@dimen/item_padding"
            android:scaleType="fitCenter" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="10"
            android:background="#EEE"
            android:orientation="horizontal" >
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="80"
                android:background="#000"
                android:orientation="horizontal" >
            </LinearLayout>
    
            <ImageView
                android:id="@+id/ivShare"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="20"
                android:background="#ddd"
                android:padding="@dimen/item_padding"
                android:scaleType="fitCenter" />
        </LinearLayout>
    
    </LinearLayout>
    

1 个答案:

答案 0 :(得分:1)

ScrollView身高从fill_parent更改为wrap_content。因为android:layout_height="fill_parent"您的ScrollView会超过您的llFooterPlaceholder

像这样

<ScrollView
        android:id="@+id/svContent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/llFooterPlaceholder"
        android:layout_alignParentTop="true" >

        <!-- Inflate the contents of the ScrollView dynamicaly -->
</ScrollView>
相关问题