ScrollView in custom dailog is filling the screen - android

Am having an issue how to appropriate set my scorll view for my two TextView Peaks and Peak_index. Basically they are filling all my custom dailog and not showing the delete button and cancel button. I want the scrollView for both my results at Peaks and Peak_index, but the scrollView is effecting on the two button and not showing on the dialog. What should I do in this case? Also the peaks are taking so much space from the dialog. why is that?. http://postimg.org/image/pk3qluwut/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#2196F3"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/back"
android:text="Peaks in KPa"
android:textColor="#040307" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/back"
android:text="time in sec."
android:textColor="#040307" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#2196F3"
android:orientation="horizontal">
<TextView
android:id="#+id/Peak_Num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/back"
android:text="Peaks"
android:textColor="#040307" />
<TextView
android:id="#+id/text_Index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#drawable/back"
android:text="#string/Peaks_index"
android:textColor="#040307" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="3dp">
<Button
android:id="#+id/button_Del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#drawable/button"
android:text="Delete File" />
<Button
android:id="#+id/button_Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#drawable/button"
android:text="Cancel" />
</LinearLayout>

This is because scrollview height is match parent, it should be wrap_content or 0 or fixed value.

Related

Android RecyclerView : Setting a view at the bottom of each row of recyclerView.

I have a view that works as a footer of each row of recyclerView. What I am trying to achieve is something like this.
The image represents a row of my recyclerView.and each box a different view.
For most of the part it is obvious but I am having issues placing the the view that is represented by the yellow box at the bottom of the row.
I have tried a few different ways for example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:id="#+id/colored_penal"
android:layout_width="4dp"
android:layout_height="fill_parent"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="128"
android:textSize="24sp"/>
<TextView
android:id="#+id/unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mtr" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/hospital_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hey, this is a dummy hospital"
android:textSize="18sp" />
<TextView
android:id="#+id/hospital_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/hospital_name"
android:text="At the end of the road" />
<!--This is the yellow box view that I want at the bottom-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="8dp"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/waiting_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Waiting time: 40 mins"
android:textSize="8sp"
android:layout_weight="1"/>
<TextView
android:id="#+id/travel_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Travel time: 20 mins"
android:textSize="8sp"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I have used alignParentBottom as true yet the view is not getting placed at the bottom of the row. It makes sense that Android squeezes each row to make sure it looks like a recyclerView but than how to put something at the bottom?
I also tried setting up layout_height="fill_parent" and gravity="bottom" for the LinearLayout (yellow view) despite knowing fill_parent is deprecated but it didn't work anyways.
Would appreciate any input helping me achieve this.
I just optimized layout. You need to specify your own View Components and attributes like maxLines or textSizes and etc. Its layout-ready.
<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="100dp"
android:orientation="horizontal">
<View
android:layout_width="10dp"
android:layout_height="match_parent"/>
<View
android:layout_width="100dp"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Content"/>
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Footer"/>
</LinearLayout>
Good luck there
Emre
This might do what you are looking for
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="128"
android:textSize="24sp" />
<TextView
android:id="#+id/unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mtr" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="#+id/hospital_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hey, this is a dummy hospital"
android:textSize="18sp" />
<TextView
android:id="#+id/hospital_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/hospital_name"
android:text="At the end of the road" />
<!--This is the yellow box view that I want at the bottom-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/hospital_address">
<TextView
android:id="#+id/waiting_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Waiting time: 40 mins"
android:textSize="8sp" />
<TextView
android:id="#+id/travel_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Travel time: 20 mins"
android:textSize="8sp" />
</LinearLayout>
<View
android:id="#+id/colored_penal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="#+id/hospital_address"
android:layout_marginTop="10dp" />
</RelativeLayout>
</LinearLayout>

Combine two LinearLayouts into one LinearLayout

I have an twoLinearLayout inside the RelativeLayout. I just want to do this LinearLayout inside the one LinearLayout so that my child control will display inside 1 LinearLayout. so that I can make group of this LinearLayout and display
with differnt background color android:background="#drawable/my_custom_background so that all child control coupled into it.
see the below screen shot
code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#0B95BA"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:id="#+id/linearLayoutCont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/txtViewCont"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Contact Billing"
android:gravity="center"
android:textSize="25sp"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutContBillingCall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/linearLayoutCont"
android:layout_marginTop="5dp">
<Button
android:text="Call"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_gravity="right"
android:background="#drawable/ButtonStyle"
android:id="#+id/btnContCall"
android:drawableLeft="#drawable/PhoneCall" />
<Button
android:text="Email"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_gravity="right"
android:background="#drawable/ButtonStyle"
android:id="#+id/btnEmail"
android:drawableLeft="#drawable/Email" />
</LinearLayout>
</RelativeLayout>
and o/p should be above pic like Contact at center and two button (Call and Email) are below the contact same corner. also one thing I want to ask how I can create a space between these two buttons.
You need to only take one Linear Layout instead of two. Your Text View is child of your Relative Layout. I have applied some Modification to your Layout.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0B95BA">
<TextView
android:id="#+id/txtViewCont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="center"
android:text="Contact Billing"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtViewCont"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btnContCall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="5dp"
android:text="Call"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="5dp"
android:text="Email"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
Note : Apply your own Drawables and Background as you have in your OP.
Replace relative with linear you will get your desired output.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0B95BA"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:id="#+id/linearLayoutCont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/txtViewCont"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Contact Billing"
android:gravity="center"
android:textSize="25sp"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutContBillingCall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/linearLayoutCont"
android:layout_marginTop="5dp">
<Button
android:text="Call"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_gravity="right"
android:background="#drawable/ButtonStyle"
android:id="#+id/btnContCall"
android:drawableLeft="#drawable/PhoneCall" />
<Button
android:text="Email"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_gravity="right"
android:background="#drawable/ButtonStyle"
android:id="#+id/btnEmail"
android:drawableLeft="#drawable/Email" />
</LinearLayout>
</LinearLayout>

Android dialog with ListView

I have a problem with a dialog with some buttons and a ListView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical"
tools:context=".MyApplicationActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/selectContactRecord"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnContactPickerAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableLeft="#android:drawable/ic_menu_add"
android:drawableStart="#android:drawable/ic_menu_add"
android:text="#string/noContact" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/selectBulbs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item" >
</ListView>
<Button
android:id="#+id/btnTestAddRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/test_bulbs"
android:drawableStart="#drawable/test_bulbs"
android:text="#string/test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="#android:color/black"
android:orientation="horizontal" >
<Button
android:id="#+id/btnCancelAddRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_revert"
android:drawableStart="#android:drawable/ic_menu_revert"
android:text="#string/cancel" />
<Button
android:id="#+id/btnSaveAddRecord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_save"
android:drawableStart="#android:drawable/ic_menu_save"
android:text="#string/save" />
</LinearLayout>
The problem is now, if I have a lot of records in the ListView, the button below disappears and it is not possible to scroll down.
I tried this with a ScrollView, but failed because it is not possible to use that with a ListView.
I want that the buttons below the listview always stay at the bottom and that the ListView is scrollable.
Can somebody please give me a hint?
Change your list view to this:
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item"
It'll make sure the button is layout in the bottom and, the list view take all the height remain
You want this :
I want that the buttons below the listview always stay at the bottom
and that the ListView is scrollable.
For this change this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black">
<TextView
android:id="#+id/tvContactRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/selectContactRecord"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnContactPickerAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableLeft="#android:drawable/ic_menu_add"
android:drawableStart="#android:drawable/ic_menu_add"
android:text="#string/noContact"
android:layout_below="#+id/tvContactRecord" />
<TextView
android:id="#+id/tvSelectBulbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/selectBulbs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white"
android:layout_below="#+id/btnContactPickerAdd" />
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item"
android:layout_below="#+id/tvSelectBulbs"
android:layout_above="#+id/btnTestAddRecord" >
</ListView>
<Button
android:id="#+id/btnTestAddRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/test_bulbs"
android:drawableStart="#drawable/test_bulbs"
android:text="#string/test"
android:layout_above="#+id/llBottom" />
<LinearLayout
android:id="#+id/llBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="#android:color/black"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/btnCancelAddRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_revert"
android:drawableStart="#android:drawable/ic_menu_revert"
android:text="#string/cancel" />
<Button
android:id="#+id/btnSaveAddRecord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_save"
android:drawableStart="#android:drawable/ic_menu_save"
android:text="#string/save" />
</LinearLayout>
</RelativeLayout>
You can consider below layout for the solution. You can replace Buttons as per your need.(I have given 2 buttons to simplify the things for you) Also you can also consider taking the buttons in another layout as well if required.
<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >
<Button
android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="My Button 2" />
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/btn2"
android:text="My Button 1" />
<ListView
android:id="#+id/lstMyListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/btn1" />
</RelativeLayout>

How to disable or block TextView to not narrowed other elements of the Layout

I have problem with my TextView, when something is written in it. It narrows the right layout.
like here:
1 Without something is written: http://i.stack.imgur.com/zItJw.jpg
2.Without something is written in: http://i.stack.imgur.com/b5Nb4.jpg
My Layout Code:
1st bar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/dzialanie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="X razy Y" />
<TextView
android:id="#+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="25sp"
android:text="=" />
<TextView
android:id="#+id/tylemabyc"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
2nd bar
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/czas"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
3rd bar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:background="#drawable/czas_punkty_bez_napisu"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/wynik"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
How to block 1st TextView to not narrows others ?
You can use layout_weight property to tell android how much space each textView takes on the screen. If you want all of them to have the same space you can add the layout_weight of 1 for all of them.
You will also need to readjust your layout_width too. You will have to trade off for the layout_heght. For example if i want 4 textviews in a horizontal line holding equal space "Horizontally" i would do something like this:
<?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:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="This is verrry long text" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="maybe not" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="let us see" />
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ok" />

Android fix the image size

In my screen I am having 3 buttons and in next row below those buttons I am having 3 names (name corresponding to those buttons) but my problem is that when ever name changes then size of buttons also changes but I do want to fix the size of buttons here is my code please help me
<TableLayout android:background="#drawable/toptab"
android:layout_width="fill_parent" android:id="#+id/tableLayout"
android:layout_height="wrap_content"
android:stretchColumns="1" android:gravity="center_vertical"
android:layout_alignParentBottom="true">
<TableRow>
<ImageButton android:id="#+id/btnPrev" android:background="#drawable/imgPrev"
android:layout_marginLeft="5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageButton android:id="#+id/btnRefresh"
android:layout_gravity="center" android:background="#drawable/refreshbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton android:id="#+id/btnNext"
android:background="#drawable/imgNext"
android:layout_width="5dp"
android:layout_height="20dp"
android:layout_marginRight="5dp" />
</TableRow>
<TableRow >
<TextView android:id="#+id/prev" android:text="Hk" android:layout_marginLeft="5dp" />
<TextView android:id="#+id/refresh" android:text="Refresh" android:layout_gravity="center" />
<TextView android:id="#+id/next" android:text="RS" android:layout_marginRight="5dp" />
</TableRow>
</TableLayout>
If you want to avoid fixing button size, then I would recommend using different layout than TableLayout, maybe RelativeLayout and TextViews with property alignBaseline or LinearLayout with weight properties could do the trick.
You should use linearlayout instead of table layout and use Weight property for aligning buttons and text view in equal dimensions, so here if you write more text in text view , button size will not increase. Also you can add more buttons in same manner. Below is the XML file and screen shot.
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" android:gravity="center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextViewTextTextViewTextTextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" android:gravity="center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" android:gravity="center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>

Categories

Resources