tags:

views:

77

answers:

4

I am facing problem to customize Linear Layout. My xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    >

     <LinearLayout android:id="@+id/LinearLayout_LeftPanel" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:background="#0000ff"    
        >
        <TextView android:id="@+id/LeftPanel_Title"
             android:text="Frequently asked questions"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textColor="#000000"
            />

    </LinearLayout>


    <LinearLayout android:id="@+id/LinearLayout_MainContent"        
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"        
        android:gravity="center"
        android:layout_toRightOf="@+id/LinearLayout_LeftPanel"      
        >
        <TextView android:id="@+id/MainContent_Title"
             android:text="Alabama Rules of Civil Procedure"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content" 
             android:textColor="#ff0000"
             android:textSize="19px"
             android:textStyle="bold"
             />     
    </LinearLayout>

</RelativeLayout>

I want to set the width of @+id/LinearLayout_LeftPanel layout one third of the screen width pro-grammatically on the onCreate(). so how can do this ?

A: 

you can use set the weight property of both Linearlayouts

set the first android:layout_weight="1" and the left panel android:layout_weight="3"

thanks

Mina Samy
A: 

Thanks for your quick reply. But the suggestion is not working well. I have set the values as usual. But not working.

By the by, how can i set the text "Frequently asked questions" as "Frequently aske....".

Can you please give me the solution?

Thanks in advance. gsmaker

gsmaker
Use "Add comment" instead of answer a question when you're not answering it.
Charlie Sheen
Hi, Charli Sheen, I am so sorry for that type of answer. I am novice developer and i do not know about this site. And I am sure next time i will not do the same thing. Thanks for your advice.
gsmaker
+1  A: 

The answer from Mina Samy is almost correct, but you're using a RelativeLayout as your topmost container. The android:layout_weight attribute only works when the surrounding container is a LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&gt;

       <LinearLayout android:id="@+id/LeftPanel"
                     android:layout_weight="1">
            ...
       </LinearLayout>

       <LinearLayout android:id="@+id/MainContent"
                     android:layout_weight="3">
            ...
       </LinearLayout>

</LinearLayout>

EDIT: I just saw that you said you wanted to set it "programmatically in the onCreate method". If you really want to do this instead of setting it in the XML like I wrote above, you have to do do something like this:

protected void onCreate(Bundle b) {
    LinearLayout leftPanel = (LinearLayout)findViewById(R.id.LeftPanel);
    LinearLayout.LayoutParams leftPanelParams = (LinearLayout.LayoutParams)leftPanel.getLayoutParams();
    leftPanelParams.weight = 1;

    // do the same thing for MainContent but set the Weight to 3;
}
Matthias Schippling
A: 

Thanks again for reply. Though the answers are working but I am not getting the actual out what i want to do.

By the by I have tried by the following code to get the actual out.

LinearLayout mainLayout = (LinearLayout)findViewById(R.id.LinearLayout_LeftPanel);
mainLayout.setMinimumWidth(screenWidth/3);

but it is not working well. Why the code is not working? If any one know the solution please tell me. or If there is any code like that please post the code on the answer.

Best Regards, gsmaker

gsmaker
Like Charlie Sheen already said: Please use the "comment" link under the answer that doesn't quite work to add a comment instead of adding an answer. This is not a forum. If you have additional information to your question, please edit your question instead of adding answers. The answers are for (possible) solutions, not further questions.
Matthias Schippling