Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is not possible for linear layout to have style attributes

I have defined a style for Linear layout but the layout is not visible in graphical view of main.xml


main.xml.

<LinearLayout style="VerticalThemeLayoutInputs">

styles.xml

<resources>
<style name="VerticalThemeLayoutInputs">
    <item name="android:background">#6699FF</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>

</style>
</resources>

Edit:

But below code will work fine but I don't want this code

<LinearLayout
android:background="#6699FF"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

Interesting Fact

I used a scrollview. Within that I placed many Linear layout. Layouts properties are almost same so I decided to have a style for that. But what is happening know? the layout is not visible only in graphical-view but it works fine in emulator.

But actually what is happening? I think its due to Scroll view.

like image 671
vnshetty Avatar asked Jul 28 '11 06:07

vnshetty


People also ask

What is the difference between linear layout and relative layout?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.

What is a linear layout?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

Which is better constraint layout or linear layout?

ConstraintLayout helps you to avoid using nested layouts and it causes better performance. it's not wrong to use it for everything but if you know that you are not going to have nested layouts, for example, three Textview s respectively, you can use LinearLayout.

Can we use constraint layout inside linear layout?

With the help of ConstraintLayout, we can position our UI components in any sort of order whether it may be horizontal or vertical. But in the case of Linear Layout, we can only arrange our UI components either in a horizontal or in a vertical manner.


1 Answers

I think what you want is style="@style/VerticalThemeLayoutInputs".

E.g.

<LinearLayout
    style="@style/VerticalThemeLayoutInputs">
like image 69
Steve Prentice Avatar answered Oct 24 '22 08:10

Steve Prentice