Unable to resize images in LinearLayout and Weight property set - java

I'm trying to resize the images and increase the icon size however I have added them to a LinearLayout and each 5 icons share the weight. They fit by themselves thus making it impossible for me to increase their icon size/height/width.
A Snapshot:
Here's my XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="horizontal"
android:weightSum="5">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/feed_blue" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/compass" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/circle_blue" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/heart_beat" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/user_icon_female" />
</LinearLayout>
I need to increase/decrease the size of my icons as I wish but the Weight property is probably limiting that ability. How can I get that done folks?

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="horizontal"
android:weightSum="5">
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/feed_blue" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/compass" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/circle_blue" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/heart_beat" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/user_icon_female" />
</LinearLayout>
In this situation they all have %20 percent of total width you can change width easily by changing weight. And also you can change width and height using padding property.

For normal app you need images pack for all android resources like mipmap-hdpi, mipmap-mdpi, mipmap-nodpi, mipmap-xhdpi, mipmap-xxhdpi, mipmap-xxxhdpi and you should not change image size programmatically, if you have not image pack try to play vs android:scaleType in all buttons for example android:scaleType="centerCrop"

Related

LinearLayout not responsive in small devices

I have a layout file in my Android application:
<?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="match_parent"
android:layout_height="match_parent"
android:background="#color/player_background"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".Fragments.PlayerFragment">
<ProgressBar
android:id="#+id/progress_bar_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:theme="#style/ProgressBarStyle"
android:visibility="invisible" />
<TextView
android:id="#+id/title_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Title"
android:textColor="#color/white"
android:textSize="24dp" />
<ImageView
android:id="#+id/view_imageview"
android:layout_width="280dp"
android:layout_height="280dp"
android:layout_marginTop="10dp"
android:background="#color/white" />
<TextView
android:id="#+id/status_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="20dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageButton
android:id="#+id/play_pause_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/play_btn" />
<ImageButton
android:id="#+id/sleep_timer_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/sleep_btn" />
<ImageButton
android:id="#+id/share_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:layout_toLeftOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/share_btn" />
<TextView
android:id="#+id/sleep_timer_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sleep_timer_btn"
android:layout_alignLeft="#+id/sleep_timer_btn"
android:layout_alignRight="#+id/sleep_timer_btn"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="15dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/volume_seek_bar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:theme="#style/Volume_Seekbar"
android:paddingStart="30dp"
android:paddingEnd="30dp"/>
</LinearLayout>
It's working perfectly in most of the devices but in a small screen device I can't see the SeekBar because it's out from the screen. Any idea how I can fix it?
You are using very large fixed sizes on your views, and because different phones got different screen sizes what seems to work on some device will actually not work on another
For example - in a smaller device with height of 300dp with views summing up to total of 400dp you will not have enough room for some views because of the small screen size and that's why you are not seeing your view.
You can use ConstraintLayout to make your screen responsive, or if you want to keep your current layout structure you can use the following libraries for scaling size of dp:
ssp and sdp to get a scalable size unit for your views and texts.
Another option is to wrap your layout with ScrollView, giving your screen the option to be scrollable and by that you will be able to "see" all of your views on your screen - note that this may not be intuitive to your user.
It is because the fixed sizes you are using to build your layout is getting summed up eventually being too big for small screen size. You can try the following to fix this:
Create a layout specially for small screen size by using smallest width qualifier
Make your layout scrollable
Use constraint layout
Using the ssp and sdp size units
NOTE that you will have to specify the smallest width qualifier to your current layout in such a way that the smallest width qualifer excludes the small screen devices and include the devices in which your layout fits properly.
I would suggest you to use constraint layout, but if you still want to go ahead with your current view then it will be good practice if you add scrollview to your parent layout, so that your layout won't get cropped on smaller devices:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/player_background"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".Fragments.PlayerFragment">
<ProgressBar
android:id="#+id/progress_bar_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:theme="#style/ProgressBarStyle"
android:visibility="invisible" />
<TextView
android:id="#+id/title_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Title"
android:textColor="#color/white"
android:textSize="24dp" />
<ImageView
android:id="#+id/view_imageview"
android:layout_width="280dp"
android:layout_height="280dp"
android:layout_marginTop="10dp"
android:background="#color/white" />
<TextView
android:id="#+id/status_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="20dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageButton
android:id="#+id/play_pause_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/play_btn" />
<ImageButton
android:id="#+id/sleep_timer_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/sleep_btn" />
<ImageButton
android:id="#+id/share_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:layout_toLeftOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/share_btn" />
<TextView
android:id="#+id/sleep_timer_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sleep_timer_btn"
android:layout_alignLeft="#+id/sleep_timer_btn"
android:layout_alignRight="#+id/sleep_timer_btn"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="15dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/volume_seek_bar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:theme="#style/Volume_Seekbar" />
</LinearLayout>
</ScrollView>

How can I conditionally 'remove' or hide a button?

I have a fragment containing a recyclerView.
When an item is clicked on in the recyclerView I set the recyclerview item background to green and change the "saveBtn" text to "Update".
I need to also be able to remove the "deletebtn" every time a user clicks on a recyclerView item, or hide it so that the UI looks somewhat like this:
How could this be done?
Method I am using to update UI on recyclerView click
public void onExerciseClicked(int position) {
saveBtn.setText("Update");
clearBtn.setText("Delete");
}
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradientfrozen"
android:id="#+id/constraint_layout21">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#292929"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView5"
android:layout_width="327dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="20dp"
android:layout_marginTop="10dp"
android:text="WEIGHT (kgs)"
android:textColor="#android:color/background_light"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="horizontal">
<Button
android:id="#+id/dec_weight"
android:layout_width="1dp"
android:layout_height="50dp"
android:layout_weight="0.5"
android:background="#drawable/down22"
android:textColor="#color/design_default_color_background" />
<EditText
android:id="#+id/editTextWeight"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:backgroundTint="#color/green"
android:ems="10"
android:gravity="center"
android:hint="0.0"
android:inputType="numberDecimal"
android:singleLine="false"
android:textColor="#color/design_default_color_background"
android:textColorHint="#color/light_grey"
android:textSize="30sp" />
<Button
android:id="#+id/inc_weight"
android:layout_width="1dp"
android:layout_height="50dp"
android:layout_weight="0.5"
android:background="#drawable/up22" />
</LinearLayout>
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="REPS"
android:textColor="#android:color/background_light"
android:textSize="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="horizontal">
<Button
android:id="#+id/dec_reps"
android:layout_width="1dp"
android:layout_height="50dp"
android:layout_weight="1.6"
android:background="#drawable/down22"
android:shadowColor="#color/design_default_color_background" />
<EditText
android:id="#+id/editTextReps"
android:layout_width="161dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:backgroundTint="#color/green"
android:ems="10"
android:gravity="center"
android:hint="0"
android:inputType="number"
android:textColor="#color/design_default_color_background"
android:textColorHint="#color/light_grey"
android:textSize="30sp" />
<Button
android:id="#+id/inc_reps"
android:layout_width="1dp"
android:layout_height="50dp"
android:layout_weight="1.6"
android:background="#drawable/up22" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal">
<Button
android:id="#+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:background="#drawable/my_small_green_shape"
android:text="Save"
android:textColor="#ffffff"
android:textSize="20sp" />
<Button
android:id="#+id/clear_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:background="#drawable/my_small_red_shape"
android:text="Clear"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Set"
android:textColor="#android:color/holo_green_light" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Kgs"
android:textColor="#android:color/holo_green_light" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Reps"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/completed_exercise_ListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:background="#292929"
tools:listitem="#layout/completed_exercise_item" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Using LinearLayout as a direct child of ConstraintLayout defeats the whole purpose of using ConstraintLayout. It is not a good practice to use nested layout from the performance point of view. Besides, if deleteBtn is direct child of ConstraintLayout, then setting the layout_width of saveBtn to match_constraint will enable it to take up the whole space if we change the visibility of deleteBtn to gone.
cgb_pandey's answer is great and it is the recommended approach since your root viewgroup is ConstraintLayout. However, I wanted to present you an alternative way to do this using your current LinearLayout approach.
All you need to do is to set the width of both bottoms to 0dp. This way, their weight would determine how much space they occupy. If both view are visible, each of them would have 50% of the total width of the screen. If only one of the buttons is visible, it would occupy the entire screen. Here's a code snippet to guide you:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal">
<Button
android:id="#+id/save_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:background="#drawable/my_small_green_shape"
android:text="Save"
android:textColor="#ffffff"
android:textSize="20sp" />
<Button
android:id="#+id/clear_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:background="#drawable/my_small_red_shape"
android:text="Clear"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
Not that this approach involves nesting layouts and this might affect performance in the long run and also complicate your layout code pretty fast.

Image out of imageview on app startup

Image is set out of imageview on app startup as shown in screenshot and fixes automatically on imageview click.
[![enter image description here][1]][1]
I need to fit image on startup itself.
Sorry,if i wasnt able to ask question properly.if any doubts pls ask me.
item_list.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">
<CheckBox
android:id="#+id/checkboxItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.2"
android:textSize="16sp"
tools:text="Tea" />
<LinearLayout
android:id="#+id/linearRate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.8"
android:gravity="center">
<com.mikepenz.iconics.view.IconicsImageView
android:id="#+id/textSubtractRate"
android:layout_width="30dp"
android:layout_height="30dp"
app:iiv_color="#color/md_grey_400"
/>
<EditText
android:id="#+id/textRate"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:digits="0123456789"
android:gravity="center"
android:inputType="number|textNoSuggestions"
android:singleLine="true"
android:textSize="18sp"
tools:text="3" />
<com.mikepenz.iconics.view.IconicsImageView
android:id="#+id/textAddRate"
android:layout_width="30dp"
android:layout_height="30dp"
app:iiv_color="#color/md_green_600"
app:iiv_icon="faw_plus_circle"
app:iiv_size="25sp" />
</LinearLayout>
</LinearLayout>
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">
<CheckBox
android:id="#+id/checkboxItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.2"
android:textSize="16sp"
tools:text="Tea" />
<LinearLayout
android:id="#+id/linearRate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.8"
android:gravity="center">
<ImageView
android:id="#+id/textSubtractRate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#mipmap/ic_launcher"/>
<EditText
android:id="#+id/textRate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:digits="0123456789"
android:gravity="center"
android:inputType="number|textNoSuggestions"
android:singleLine="true"
android:textSize="18sp"
tools:text="3" />
<ImageView
android:id="#+id/textAddRate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
Because your linearRate layout's weight width (0.8) is not enough for the images and the text.
If your intention for using layout_weight is for giving the rest of the empty space for the Checkbox, remove the android:weightSum="2" from the root layout, remove the weight from linearRate, and make checkboxItem's weight 1.
Please check this and let us know your feedback..
<?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="match_parent"
android:layout_height="?attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:weightSum="100">
<CheckBox
android:id="#+id/checkboxItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60"
android:textSize="16sp"
tools:text="Tea" />
<LinearLayout
android:id="#+id/linearRate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:gravity="center">
<ImageView
android:id="#+id/textSubtractRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_indeterminate_check_box" />
<EditText
android:id="#+id/textRate"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:digits="0123456789"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:inputType="number|textNoSuggestions"
android:singleLine="true"
android:textSize="18sp"
tools:text="3" />
<ImageView
android:id="#+id/textAddRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_box" />
</LinearLayout>
</LinearLayout>

Android -alert dialog design

In my application I want to show popup dialog. I drew sketch for first phase. and here what I want:
I was trying to implement this and here is my code:
<TableLayout 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:shrinkColumns="*"
android:stretchColumns="*"
android:background="#ffffff"
tools:context=".CustomMainActivity" >
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:background="#b6006a">
<ImageView
android:id="#+id/ImageView1"
android:src="#drawable/icon"
android:layout_weight="1"
android:padding="10dip"
android:adjustViewBounds="true"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="fitXY"
android:gravity="right"/>
<TextView
android:id="#+id/TextView1"
android:layout_weight="1"
android:textSize="18dp"
android:text="Nava Messenger"
android:padding="10dip"
android:background="#b6006a"
android:textColor="#fff"
android:gravity="left"/>
</TableRow>
<TableRow
android:id="#+id/tableRow0"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:id="#+id/TextViewSender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_span="3"
android:maxLines="1"
android:background="#fff"
android:textColor="#000"/>
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:id="#+id/TextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_span="3"
android:maxLines="4"
android:padding="18dip"
android:background="#fff"
android:textColor="#000"/>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<EditText
android:id="#+id/EditText1"
android:layout_weight="3"
android:inputType="textCapWords"
android:layout_width="0dp"
android:ellipsize="start"
android:gravity="center"
android:textColor="#b6006a"
android:hint="Write a message..."/>
<ImageButton
android:id="#+id/ImageButton1"
android:layout_weight="1"
android:layout_width="0dp"
android:adjustViewBounds="true"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/send_now"
android:gravity="right"/>
</TableRow>
</TableLayout>
And result of this code is :
I want to modify something such as:
Decreasing header size(purple area on the top of alert dialog)
Decreasing image size on header (Real size of logo image is :128*128)
Decreasing send image (Real size of send image is : 48 * 48)
Putting send image and EditText on a row
Any suggestion?
Using LinearLayout Adjust Margin/Padding as required. change icons aswell. rough layout.
<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:background="#ffffff"
android:orientation="vertical"
tools:context=".CustomMainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b6006a"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:id="#+id/ImageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:gravity="right"
android:padding="10dip"
android:scaleType="fitXY"
android:src="#android:drawable/ic_dialog_dialer" />
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#b6006a"
android:gravity="left"
android:padding="10dip"
android:text="Nava Messenger"
android:textColor="#fff"
android:textSize="18dp" />
</LinearLayout>
<TextView
android:id="#+id/TextViewSender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:maxLines="1"
android:text="Farhan"
android:textColor="#000"
android:textSize="18dp" />
<TextView
android:id="#+id/TextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:maxLines="4"
android:text="FarhanFarhanFarhan"
android:padding="18dip"
android:textColor="#000"
android:textSize="18dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<EditText
android:id="#+id/EditText1"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"
android:ellipsize="start"
android:gravity="center"
android:hint="Write a message..."
android:inputType="textCapWords"
android:textColor="#b6006a" />
<ImageButton
android:id="#+id/ImageButton1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#null"
android:gravity="right"
android:scaleType="center"
android:src="#android:drawable/ic_menu_send" />
</LinearLayout>
</LinearLayout>
Use RelativeLayout instead TableLayout, it's much easier to use RelativeLayout.
Change width and height for image sizes triying other values of ScaleType if it were neccesary.
If you want to control header's size, don't use "wrap_content".
Define colors in values/colors.xml.

horizontal scrolling for list of images

I have tried to make a Horizontal scrolling of list of 5 images in my app.I wrote the following XML in my app. The problem that i am facing is it leaves a blank
area to the left and right of the screen ,i.e is blamk area before the image list starts and some blank area after the image list .
XML
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
</LinearLayout>
</HorizontalScrollView>
Can anyone Help me how to remove this unwanted blank area ?
I tried NagarjunaReddy suggestion, but I got the result as shown in screenshot below.
I got the answer to my question .Actually this blank space is coming because of my mobile system operating system android versin 4.0. I checked my same app in android ver2.3 there i dint get any blank space anyways.
Remove android:paddingRight="20dp" for all the <ImageView>s
try this remove pading for all imageviews android:paddingRight="20dp"
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
</LinearLayout>
It should have nothing to do with the OS version.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
</LinearLayout>
You should get something like this:

Categories

Resources