S
S
Sergey2015-01-12 15:46:48
Android
Sergey, 2015-01-12 15:46:48

How to programmatically set the width of a LinearLayout?

There is a slider source and a lesson at the link: www.oodlestechnologies.com/blogs/Facebook-Style-Sl...
In this case, the width of the "left_menu.xml" file is determined by the TextView (android:layout_width="260dp")
How do I set the width for "LinearLayout" of "left_menu.xml" file depending on device screen? For example, I want the width of the "LinearLayout" to always be 1/3 of the device's screen? Or any way to set TextView width to 1/3 of device screen width.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2015-01-12
@googlgan

Solution found:
stackoverflow.com/questions/27903041/how-to-program...

B
Billy Milligan, 2015-01-12
@Billy_Milligan

Sorry, there is no Android Studio at hand, I hope you understood the essence, I wrote on my knee;)
I hope it helped)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/MyLayout"
    android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="0.33">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="0.33">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="0.33">
    </RelativeLayout>
</LinearLayout>

A
Andriy Biskup, 2015-01-12
@AndriyTheProgrammer

If you need to proportionally place the elements on the screen, then it is better and easier to not find weight.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question