krinn
krinn

Reputation: 892

making android layout, wrong width

Can anyone tell me how to create layout like that? I have problem with the middle element. enter image description here

Upvotes: 0

Views: 144

Answers (4)

Sam
Sam

Reputation: 86958

Simply use the layout_margin attribute in any element, for example TextView:

<TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="60dp"
    android:layout_marginRight="60dp"
    android:background="#ff0000" />

Upvotes: 0

I&#241;igo
I&#241;igo

Reputation: 12823

Do you need just the middle view or the three of them?

For the former, just create a view with 60dp padding in the left and right sides.

For the latter, create the edge views, fixed, with 60dp width, and for the middle one, set the following attributes: 0dp of layout_width, and 1 of layout_weight.

And put all these Views inside a LinearLayout.

Upvotes: 1

Santacrab
Santacrab

Reputation: 3195

A Linear layout with 3 elements inside:

the left and right elemend will have android:layout_width="60dp" while the central one will have:

android:layout_width="0dp"
android:layout_weight="1"

in this way it'll adapt to the device screen width

Upvotes: 0

sdabet
sdabet

Reputation: 18670

<?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="60dp"
   android:orientation="horizontal" >

   <FrameLayout
    android:layout_width="60dp" 
    android:layout_height="fill_parent"
    android:background="#333333"
    />

   <FrameLayout
    android:layout_width="0dp" 
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="#FF3333"
    />

   <FrameLayout
    android:layout_width="60dp" 
    android:layout_height="fill_parent"
    android:background="#333333"
    />

</LinearLayout>

Upvotes: 1

Related Questions