Xin lỗi về việc xuất mã lớn, nhưng tôi thực sự bị mất.Phân đoạn Android không tôn trọng match_parent là chiều cao
MyActivity.java onCreate:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_singlepane_empty);
mFragment = new PlacesFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.root_container, mFragment)
.commit();
PlacesFragment.java onCreateView:
mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null);
return mRootView;
Ghi chú: mRootView là một ViewGroup toàn cầu, không có vấn đề về điều đó, tôi tin. PlacesFragment là một ListFragment.
Layouts:
activity_singlepane_empty.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00f">
<include layout="@layout/actionbar"/>
<!-- FRAGMENTS COME HERE! See match_parent above -->
</LinearLayout>
list_content.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listContainer"
android:background="#990"
>
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
<TextView android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/no_data_suggest_connection"/>
</FrameLayout>
Vấn đề: như bạn có thể thấy, hành vi mong đợi sẽ có những sản phẩm nào TextView ở trên xuất hiện ở giữa màn hình. Trên bản xem trước thiết kế trong Eclipse, nó là OK. Chỉ khi được thêm vào root_view dưới dạng một đoạn, FrameLayout sẽ không lấp đầy toàn bộ màn hình.
root_container màu xanh lam và FrameLayout có màu vàng, xem bên dưới để biết mục đích gỡ lỗi. Không phải khung màu vàng sẽ lấp đầy toàn bộ màn hình?!?!?!?
Nếu bạn sử dụng chế độ xem ScrollView: http://stackoverflow.com/questions/10211338/view-inside-scrollview-doesnt-take-all-place –