Spacing between elements in LinearLayout

by Rohit » Fri, 06 Mar 2009 07:14:26 GMT


Sponsored Links
 How do I reduce the spacing between the elements in a linear layout?
I tried to set the padding to 0 as well as the vertical spacing but
that didnt seem to help. I want the textview and the imageview to be
flush together with no space between them. The following is my XML
layout file but I dont acheive what I want with it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="0px"
        android:verticalSpacing="0px"
        android:gravity="center"
        >

        <ImageView android:id="@+id/imageid"
                           android:layout_width="107px"
                           android:layout_height="100px"
                           android:gravity="center"
                           android:padding="0px"
                           android:verticalSpacing="0px"
                           />

        <TextView android:id="@+id/textid"
                          android:layout_width="107px"
                          android:layout_height="25px"
                          android:background="#c3c3c3"
                          android:textColor="#000000"
                          android:shadowColor="#ffffff"
                          android:shadowRadius="3"
                          android:gravity="center"
                          android:padding="0px"
                         android:verticalSpacing="0px"
                      />

</LinearLayout>


--~--~---------~--~----~------------~-------~--~----~



Spacing between elements in LinearLayout

by Rohit » Fri, 06 Mar 2009 07:15:51 GMT


 Somehow the shadow on the text also doesnt show up..

Rohit




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Spacing between elements in LinearLayout

by Rohit » Fri, 06 Mar 2009 07:30:37 GMT


 This works - I was making some mistake in my code. The shadow still
doesnt work

Rohit





--~--~---------~--~----~------------~-------~--~----~



Spacing between elements in LinearLayout

by Rohit Mordani » Sat, 07 Mar 2009 10:59:55 GMT


 How do I reduce the spacing between the elements in a linear layout?
I tried to set the padding to 0 as well as the vertical spacing but
that didnt seem to help. I want the textview and the imageview to be
flush together with no space between them. The following is my XML
layout file but I dont acheive what I want with it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="0px"
        android:verticalSpacing="0px"
        android:gravity="center"
        >

        <ImageView android:id="@+id/imageid"
                           android:layout_width="107px"
                           android:layout_height="100px"
                           android:gravity="center"
                           android:padding="0px"
                           android:verticalSpacing="0px"
                           />

        <TextView android:id="@+id/textid"
                          android:layout_width="107px"
                          android:layout_height="25px"
                          android:background="#c3c3c3"
                          android:textColor="#000000"
                          android:shadowColor="#ffffff"
                          android:shadowRadius="3"
                          android:gravity="center"
                          android:padding="0px"
                         android:verticalSpacing="0px"
                      />

</LinearLayout>


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Problem with setText() on custom CheckBox

Hi,

I've implemented a custom CheckBox view and faced a probelm with
adding text to it.

Here's my implementation:

public class MyCheckBox extends CheckBox{

private int imgResourceFocusedChecked, imgResourceFocusedNotChecked,
imgResourceNotFocusedChecked, imgResourceNotFocusedNotChecked;

        public MyCheckBox(Context context){
                super(context);
        }

        public MyCheckBox(Context context, AttributeSet attrs) {
                super(context, attrs);
                init(attrs);
        }

        public MyCheckBox(Context context, AttributeSet attrs, int defStyle)
{
                super(context, attrs, defStyle);
                init(attrs);
        }

        private void init(AttributeSet attrs){
                TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.MyCheckBox);
                imgResourceFocusedChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxFocusedChecked, -1);
                imgResourceFocusedNotChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxFocusedNotChecked, -1);
                imgResourceNotFocusedChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxNotFocusedChecked, -1);
                imgResourceNotFocusedNotChecked = a.getResourceId
(R.styleable.MyCheckBox_checkboxNotFocusedNotChecked, -1);
                strResourceText = a.getResourceId
(R.styleable.MyCheckBox_checkboxText, -1);
        }

        public void onDraw(Canvas canvas){
                if (this.isChecked()){
                        if (this.isFocused()){
                                
this.setBackgroundResource(imgResourceFocusedChecked);
                        } else {
                                
this.setBackgroundResource(imgResourceNotFocusedChecked);
                        }
                } else {
                        if (this.isFocused()){
                                
this.setBackgroundResource(imgResourceFocusedNotChecked);
                        } else {
                                
this.setBackgroundResource(imgResourceNotFocusedNotChecked);
                        }
                }
        }
}


Then from my layout xml I do something like:

<MyCheckBox
        android:id="@+id/checkBox"
        android:layout_width="32px"
        android:layout_height="32px"
        android:text="This is a check box."
        cb:checkboxFocusedChecked="@drawable/cb_focused_checked"
        cb:checkboxFocusedNotChecked="@drawable/cb_focused_not_checked"
        cb:checkboxNotFocusedChecked="@drawable/cb_not_focused_checked"
        cb:checkboxNotFocusedNotChecked="@drawable/
cb_not_focused_not_checked"
        style="@style/myStyle"/>

However, the text never comes up. Using the same technique with Button
and EditText views works fine , but not with check boxes. Hope to get
an advice of how to implement the proper behaviour. Thanks!




--~--~---------~--~----~------------~-------~--~----~

2. Proximity Alert and Battery life

I wrote a simple app that uses proximity alerts and after installing
it on my G1 found that battery life have been halved at least. It's so
bad that phone needs to be recharged mid-day or it completely dies by
9pm. There is no polling of any kind - just proximity alerts (3 of
them). I tried with GPS turned off (using network triangulation for
coarse GPS location) but battery life is still abysmal.

Is there a general solution to improve battery life with proximity
alerts or the whole GPS thing is a non-starter on G1s?
--~--~---------~--~----~------------~-------~--~----~

3. Map API key distribution safety

4. HTML login form works in Android browser and fails with WebView ?

5. Launch activity from Web Browser

6. Zoom controls and WebView

7. Poor menu layout