0

私が理解できないAndroidの問題を抱えているので、ここで別の目のセットを求めています:D. 横向きのときはマップとリストビューを並べて表示し、縦向きのときはトップダウンで表示しようとしているフラグメントがあります。横向きのときは期待どおりに動作しますが、何らかの理由で、縦向きモードのときは、リストした重量よりも多くのスペースをマップが占めています。考え?以下は、横向きと縦向きの両方の xml レイアウト、フラグメント コード、現在の外観のスクリーンショットです。私の経験からすると、現在の状態ではなく、期待どおりに動作するはずです。再度、感謝します!:)

XML ランドスケープ

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayoutMapSearch"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/npecCarbon"
    android:baselineAligned="false"
    android:orientation="horizontal" >
    <FrameLayout
        android:id="@+id/placeHolderMapView"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >
    </FrameLayout>
    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >
        <ListView
            android:id="@+id/listViewTicketSearchResults"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/label_no_data"
            android:textAppearance="@android:style/TextAppearance.Medium"
            android:textColor="@color/npecWhite"
            android:visibility="gone" >
        </TextView>
    </LinearLayout>
</LinearLayout>

XML ポートレート

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayoutMapSearch"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/npecCarbon"
    android:orientation="vertical" >
    <FrameLayout
        android:id="@+id/placeHolderMapView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </FrameLayout>
    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
        <ListView
            android:id="@+id/listViewTicketSearchResults"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/label_no_data"
            android:textAppearance="@android:style/TextAppearance.Medium"
            android:textColor="@color/npecWhite"
            android:visibility="gone" >
        </TextView>
    </LinearLayout>
</LinearLayout>

フラグメントコード

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if(mapFragment == null) {
        mapFragment = SupportMapFragment.newInstance();
        mapFragment.setRetainInstance(true);
        FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.placeHolderMapView, mapFragment);
        fragmentTransaction.commit();
    }
    if(mapResults == null) {
        mapResults = new ArrayList<String>();
        mapResults.add("One");
        mapResults.add("Two");
        mapResults.add("Three");
        mapResults.add("Four");
    }
    ArrayAdapter<String> simpleAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, mapResults.toArray(new String[mapResults.size()]));
    listViewSearchResults.setAdapter(simpleAdapter);
}

スクリーンショット Imgur スクリーンショットのアルバム

更新 重量プロパティに依存せずに、必要な効果を達成できました。縦向きのレイアウトでは、マップ ビューのコンテナーにディスプレイの高さの半分に等しい高さを与えます。リスト ビューの重みが機能しているため、画面の残りの半分を自動的に埋めます。

高さコード

private void calculateNewHeightForMap() {
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    if(size.y > size.x) { //We're in portrait mode, calculate height
    LayoutParams mapParams = new LayoutParams(LayoutParams.MATCH_PARENT, size.y / 2);
    frameLayoutMapPlaceHolder.setLayoutParams(mapParams);
    }

これは技術的には常に機能しますが、同じ結果が得られますが、マップ部分の重みが無視されているように見える理由についてはまだ興味があります

4

3 に答える 3

1

layout_weight=".20"縦向きモードでリストビューに追加してみてください

于 2013-01-23T17:23:16.653 に答える
0

ルート LinearLayout に weightSum="2" を追加してみてください。

于 2013-01-23T17:51:49.787 に答える
0

SUM Uが与えた体重は関係ありません。ルートに適用される重みの合計は、100% と見なされ、ルート レイアウトで 100% と見なされ、それに従って分割する必要があります。子コンポーネントまたはステム コンポーネントにレイアウト ウェイトを適用して、ルートに応じて分割します。

于 2013-01-25T19:37:36.877 に答える