Expiredmind Expiredmind - 2 months ago 30
Android Question

Resize Fragment size in TableLayout

I want to obtain somthing like that

aim

but ive obtain this

:( .

Fragment
takes all the screen. How can i set it up for example for 500dpi height and for the list layout for the rest screen.

Question 2. Is there any posibility to ad show/hide
Button
, that will resize the
Fragment
(on show the item the
Fragment
height incresed and hide the list)

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.k.guides4art20.MainActivity"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="0"
android:orientation="vertical" >


<TableRow android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dip" >


<EditText
android:layout_height="wrap_content"
android:hint="szukaj"
android:gravity="center"
android:textSize="25sp"
android:id="@+id/search_bar"
android:layout_width="0dp"
android:layout_weight="1"
android:maxLines="1" />

<Button
android:id="@+id/filters"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="filtry"
android:textSize="15sp"
android:minHeight="0dp"
android:minWidth="10dp"
android:layout_gravity="right" />

</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="400dp"
>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.k.guides4art20.MapsActivity"
android:layout_above="@+id/textView"
android:layout_alignParentStart="true"
android:layout_span="2" />

</TableRow>

<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >


<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="2">

</ListView>
</TableRow>

</TableLayout>



Answer

Insert fragment into layout and set layout_height

      <?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="wrap_content"
    android:layout_height="wrap_content"
    tools:context="com.example.k.guides4art20.MainActivity"
    android:id="@id/main"
    android:orientation="vertical">
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/searchBarLay">
        <EditText
            android:hint="szukaj"
            android:gravity="center"
            android:textSize="25sp"
            android:id="@+id/search_bar"
            android:maxLines="1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1" />
        <Button
            android:id="@+id/filters"
            android:text="filtry"
            android:textSize="15sp"
            android:minHeight="0dp"
            android:minWidth="10dp"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:autoText="false" />
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:id="@+id/mapLay"
        android:background="@color/blue25">
        <fragment xmlns:map="http://schemas.android.com/apk/res-auto"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            tools:context="com.example.k.guides4art20.MapsActivity"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listLay">
        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
</LinearLayout>

Question 2 Yes, You can do this. By changing param Visibility.

layMap.Visibility = ViewStates.Gone;
layList.Visibility = ViewStates.Visible;
Comments