埋め込まれたグーグルマップフラグメントとマップの下の選択されたマーカーに関するいくつかの情報を使用してレイアウトを作成しようとしています。地図の下の情報は、必要なスペースだけを占め、残りのスペースを地図に提供したいと思います。
私が理解している限り、layout_weight
与えられた値に比例して、さまざまなウィジェットに余分なスペースを割り当てます。したがって、が付いたウィジェットがありlayout_weight = 1
、layout_weight = 0
最初のウィジェットが付いた別のウィジェットがすべての余分なスペースを占有し、2番目のウィジェットが必要なものだけを占める場合。したがって、2番目のウィジェットを指定するとlayout_height = wrap_content
、必要なものを取得する必要があります。ただし、実際にはそうではないようです。多くの値を変更しましたが、ウィジェットの1つがすべてのスペースを占めるか、どちらも占有しません。それらを正常に表示させることができた唯一の方法layout_height
は、2番目のウィジェットのを特定の値に設定することです。
これは問題の一部である可能性がありますがmap_frag_event_icon
、ウィジェット、、、map_frag_person
およびをmap_frag_event_details
動的に入力しています。
layout.xml
<?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="0dp"
android:layout_margin="@dimen/fragment_margins"
android:orientation="vertical">
<fragment
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_frag_google_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingBottom="@dimen/fragment_margins"
tools:context=".fragment.MapFragment"/>
<LinearLayout
android:id="@+id/map_frag_event_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/map_frag_event_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/icon_padding"
android:layout_weight="0" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="@+id/map_frag_event_person"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size"/>
<TextView
android:id="@+id/map_frag_event_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
strings.xml
<resources>
<string name="app_name">Family Map</string>
<string name="title_activity_maps">Map</string>
<dimen name="fragment_margins">8dp</dimen>
<dimen name="horizontal_layout_padding">8dp</dimen>
<dimen name="vertical_layout_padding">4dp</dimen>
<dimen name="icon_size">48sp</dimen>
<dimen name="icon_padding">8dp</dimen>
<dimen name="text_size">20sp</dimen>
<dimen name="small_text_size">14sp</dimen>
<dimen name="large_text_size">24sp</dimen>
<dimen name="map_event_layout_height">120sp</dimen>
<dimen name="map_event_icon_size">40sp</dimen>
</resources>
編集
これが私が探している一般的なデザインですが、テキストの空白をできるだけ小さくし、テキストサイズを変更する設定を作成して、下部の空白を動的にする必要があります。
可能であれば、解決策とともに何が起こっているのかを説明してください。
投稿した元のコードに2つの問題が見つかりました。最初のテストでいつ追加したかはわかりませんが、2つの致命的なエラーがありました。LinearLayout
私が持っていたルートでlayout_height = "0dp"
、それはあるべきlayout_height = "match_parent"
でした。そして、LinearLayout
その中にはTextViews
、私が持っlayout_height = "match_parent"
ていたはずの2つが含まれていましたlayout_height = "wrap_content"
。
これらの2つのエラーが修正されたので、削除に関する@MuhammadMuzammilSharifの元のコメントは機能しlayout_weight = "0"
ました。
layout.xml
<?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="match_parent"
android:layout_margin="@dimen/fragment_margins"
android:orientation="vertical">
<fragment
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_frag_google_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingBottom="@dimen/fragment_margins"
tools:context=".fragment.MapFragment"/>
<LinearLayout
android:id="@+id/map_frag_event_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/map_frag_event_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/icon_padding"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="@+id/map_frag_event_person"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size"/>
<TextView
android:id="@+id/map_frag_event_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加