2

I wanted to make resizable views when one of them is hidden. The question is already asked for iOS in the following link. I wanna make it for android. Any helps are appreciated. I wanted to add free space to three TextViev: position, stat_name, price after setting visibility hidden to count and discount

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="1dp"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="30dp"
    android:weightSum="100" >

    <TextView
        style="@style/list_titles_style"
        android:layout_weight="10"
        android:text="@string/position" />

    <TextView
        style="@style/list_titles_style"
        android:layout_weight="35"
        android:paddingLeft="15dp"
        android:text="@string/stat_name" />

    <TextView
        style="@style/list_titles_style"
        android:layout_weight="20"
        android:text="@string/price" />

    <TextView
        android:id="@+id/count_label"
        style="@style/list_titles_style"
        android:layout_weight="10"
        android:visibility="invisible"
        android:text="@string/count" />

    <TextView
        android:id="@+id/discount_label"
        style="@style/list_titles_style"
        android:visibility="invisible"
        android:layout_weight="25"
        android:text="@string/discount" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="2dp"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp"
    android:layout_marginTop="1dp"
    android:background="@drawable/border_layout"
    android:orientation="horizontal" >

    <ListView
        android:id="@+id/stats_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_marginBottom="5dp"
        android:divider="@drawable/list_divider"
        android:dividerHeight="2dp"
        android:paddingBottom="0dp"
        android:paddingLeft="10dp"
        android:paddingTop="0dp" />
</LinearLayout>

And my style here it is:

<style name="list_titles_style">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:textColor">@color/Blue</item>
    <item name="android:gravity">center</item>
    <item name="android:textSize">18sp</item>
</style>
Community
  • 1
  • 1
nAkhmedov
  • 3,522
  • 4
  • 37
  • 72

2 Answers2

5

I have gone through the provided link...To remove the left side view just set the android:visibility="gone" for the view in your xml layout file....if you want remove programmatically try view.setVisibility(View.GONE);....

Vamshi
  • 1,495
  • 1
  • 15
  • 31
2

You can achieve this using LinearLayout with match_parent parameter depending on what orientation you desire. So you might set weights for each child view and also put an stub view in order to stretch out the size.

Note that if you hide your views with INVISIBLE flag they will hold the space whereas with GONE it's like the view never been there.

Hope that helps.

william gouvea
  • 554
  • 4
  • 6