有人可以請解釋爲什麼下面的代碼片段不能按預期工作? 我不能在第一個文本視圖中使用android:layout_alignParentBottom="true"
參數,因爲這樣會將視圖置於整個屏幕的底部。Android佈局與相對佈局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/bottom_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/color_black"
android:text="AT THE BOTTOM OF THE LAYOUT"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/bottom_text_view"
android:textColor="@color/color_black"
android:text="ABOVE THE PREVIOUS TEXT VIEW"/>
</RelativeLayout>
Eclipse說@id/bottom_text_view
無法解析。
請大家在考慮,這個例子是一個真實的案例的簡化,我想提出一個按鈕的頂部更復雜的觀點,即一個可摺疊的列表視圖,並按照以下順序日曆:
- ListView控件
- 日曆
- 按鈕
,我真的很需要兩個塌陷的ListView和日曆,一旦做了什麼仍然可見應以T移至o包裝到內容。
請幫助這個東西。
在此先感謝。
編輯: 下面是我的真實案例佈局 列表視圖沒有佔用我想要的空間。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="@drawable/magnet_bkg" >
<TextView
android:id="@+id/assets_header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/view_padding"
android:gravity="center"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:text="@string/lbl_asset_manager_title"
android:textColor="@color/color_white"
android:textStyle="bold"
android:textSize="@dimen/top_title_text_size"
android:background="@drawable/dashboard_title_gradient_bg"
android:visibility="visible"/>
<!-- Use the linear layout in order to control the margins in
one place only -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/assets_list_margin_side"
android:layout_marginRight="@dimen/assets_list_margin_side"
android:layout_marginTop="@dimen/assets_list_margin_topbottom"
android:layout_marginBottom="@dimen/assets_list_margin_topbottom"
android:orientation="vertical">
<!-- The header with the asset information -->
<include
layout="@layout/activity_magnet_enterprise_company_assets_list_item"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/view_padding"
android:textColor="@color/color_white"
android:textSize="@dimen/sub_title_text_size"
android:text="@string/lbl_report_filter_section_title"
android:gravity="center"
android:singleLine="true"
android:ellipsize="end"
android:background="@color/color_title_bar"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/create_report_filter_bottom_margin"
android:gravity="bottom">
<!-- The generate report Button -->
<LinearLayout
android:id="@+id/create_report_btn_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/filter_by_date_section_layout"
android:background="@color/color_repoback_dark"
android:gravity="center"
android:padding="@dimen/view_padding">
<Button
style="@style/NormalButton"
android:onClick="onBtnCreateReportClick"
android:text="@string/lbl_button_create_report" />
</LinearLayout> <!-- end of generate report Button layout -->
<!-- The filter by date section -->
<LinearLayout
android:id="@+id/filter_by_date_section_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/filter_by_project_section_layout"
android:orientation="vertical">
<!-- Sub header with the filter by date switch control -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_subtitle_bar"
android:padding="@dimen/view_padding_large" >
<Switch
android:id="@+id/filter_by_date_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/filter_by_date_switch"
android:ellipsize="end"
android:gravity="left"
android:singleLine="true"
android:text="@string/lbl_report_filter_by_date"
android:textColor="@color/color_white"
android:textSize="@dimen/sub_title_text_size_small" />
</RelativeLayout>
<!-- The section for date selection -->
<LinearLayout
android:id="@+id/date_selection_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_repoback_dark"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="@dimen/view_padding" >
<!-- Layout FROM date -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/view_padding"
android:text="@string/lbl_report_date_from"
android:textColor="@color/color_white"
android:textSize="@dimen/small_text_size"
android:textStyle="bold" />
<DatePicker
android:id="@+id/from_date_report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:padding="@dimen/view_padding" />
</LinearLayout>
<!-- Layout TO date -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/view_padding"
android:text="@string/lbl_report_date_to"
android:textColor="@color/color_white"
android:textSize="@dimen/small_text_size"
android:textStyle="bold" />
<DatePicker
android:id="@+id/to_date_report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:padding="@dimen/view_padding" />
</LinearLayout>
</LinearLayout>
</LinearLayout> <!-- end of filter by date section layout -->
<!-- The filter by project section -->
<LinearLayout
android:id="@+id/filter_by_project_section_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Sub header with the filter by project switch control -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_subtitle_bar"
android:padding="@dimen/view_padding_large" >
<Switch
android:id="@+id/filter_by_project_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/filter_by_project_switch"
android:ellipsize="end"
android:gravity="left"
android:singleLine="true"
android:text="@string/lbl_report_filter_by_project"
android:textColor="@color/color_white"
android:textSize="@dimen/sub_title_text_size_small" />
</RelativeLayout>
<!-- The projects list view -->
<ListView
android:id="@+id/projects_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_schedule_list_bg"
android:choiceMode="singleChoice"
android:divider="@color/color_lightgray"
android:dividerHeight="1dp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
他的問題是相對佈局高度是wrap_content佈局將位於頂部而不填充父項! – k0sh 2013-02-20 09:08:59
這不適合我的情況,因爲正如我所說的,真正的用例會讓列表視圖以這種方式獲得所有可用空間。嘿,等一下也許這值得一試......我會讓你知道的。 – MadBlack 2013-02-20 09:17:14
我嘗試了使用列表視圖的解決方案,它佔用了我懷疑的所有空間。我要編輯我的帖子,以提供我真正的佈局,希望你能幫助。也許我做了一些錯誤 – MadBlack 2013-02-20 10:21:05