I made a design for my application but it runs really slow. The results that I am trying to achieve is this:
So far I have been able to achieve this result with this xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.asteam.unify.Mbajtje">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_marginRight="#dimen/general_margin"
android:layout_marginLeft="#dimen/general_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lendaText"
android:layout_marginTop="#dimen/general_margin"
android:text="Lënda:"/>
<Spinner
android:id="#+id/lendaMbajtje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lendaText"
android:textSize="#dimen/font_size"
android:background="#drawable/border_bottom"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/subjektiText"
android:layout_marginTop="#dimen/general_margin"
android:layout_below="#id/lendaMbajtje"
android:text="Subjekti:"/>
<Spinner
android:id="#+id/subjektiMbajtje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/subjektiText"
android:textSize="#dimen/font_size"
android:background="#drawable/border_bottom"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/subjektiMbajtje"
android:id="#+id/detajetMbajtjesText"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="#dimen/general_margin"
android:layout_weight="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Data e mbajtjes:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:id="#+id/dates"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dayMbajtje"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:textSize="#dimen/font_size"
android:gravity="center"
android:layout_marginRight="5dp"
android:text="12"
android:paddingBottom="#dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/monthMbajtje"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="#dimen/font_size"
android:layout_marginRight="5dp"
android:text="02"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/yearMbajtje"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="#dimen/font_size"
android:text="2016"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="#dimen/general_margin"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Ora e mbajtjes:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/hourMbajtje"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="#dimen/font_size"
android:text="22"
android:paddingBottom="#dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text=":"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:id="#+id/minutesMbajtje"
android:textSize="#dimen/font_size"
android:gravity="center"
android:text="20"
android:paddingBottom="#dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_below="#+id/detajetMbajtjesText"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="#dimen/vertical_padding"
android:id="#+id/duttyCount"
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:id="#+id/duttyView"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:layout_marginRight="#dimen/margin_spiner"
android:text="Detyra e :"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/duttyCountS"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:text="parë"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:id="#+id/checkboxPresentationLinear"
android:layout_height="wrap_content">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prezantim"
android:layout_gravity="right"
android:id="#+id/presentationDutty"
android:imeOptions="actionNext"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/duttyCount"
android:id="#+id/detajetMbajtjesPrezantimText"
android:orientation="horizontal"
android:visibility="gone"
android:showDividers="end">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="#dimen/general_margin"
android:layout_weight="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Data e prezantimit:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:id="#+id/datesPresentation"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dayPresentation"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:textSize="#dimen/font_size"
android:gravity="center"
android:layout_marginRight="5dp"
android:text="12"
android:paddingBottom="#dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/monthPresentation"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="#dimen/font_size"
android:layout_marginRight="5dp"
android:text="02"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/yearPresentation"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="#dimen/font_size"
android:text="2016"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="#dimen/general_margin"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:text="Ora e prezantimit:"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/hourPresentation"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:gravity="center"
android:textSize="#dimen/font_size"
android:text="22"
android:paddingBottom="#dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text=":"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/border_bottom"
android:layout_weight="1"
android:id="#+id/minutesPresentation"
android:textSize="#dimen/font_size"
android:gravity="center"
android:text="20"
android:paddingBottom="#dimen/padding_spiner"
android:singleLine="true"
android:inputType="number"
android:imeOptions="actionNext"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/psText"
android:layout_marginTop="#dimen/general_margin"
android:layout_below="#+id/detajetMbajtjesPrezantimText"
android:text="P.s."/>
<EditText
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="textMultiLine"
android:id="#+id/psTextArea"
android:padding="#dimen/padding_spiner"
android:layout_below="#+id/psText"
android:layout_marginTop="#dimen/padding_spiner"
android:textSize="#dimen/font_size"
android:gravity="top"
android:background="#drawable/border_textarea"
android:imeOptions="actionDone"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/previewMbajtje"
android:layout_below="#+id/psTextArea"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
I was hoping someone could tell me how I can optimize this xml code?
You have a bad layout structure that is bound for performance issues. There are many ways to optimize it, in your case:
The surrounding FrameLayout can be removed, since it just holds a ScrollView. Make the scroll view your root.
Don't use a RelativeLayout this far at the top of your layout. It will require 2 layout passes for every children. Use a LinearLayout since you are just aligning views in a vertical order
You have at least one LinearLayout that just wraps another LinearLayout. You should merge them into one.
You have a LinearLayout with weights inside another LinearLayout with weights. This also requires multiple layout passes.
There is a horizontal LinearLayout within another horizontal LinearLayout. You could probably also merge those.
There are also lots of tutorials on what to do and what not to do.
Related
I have a problem filling the entire screen in a reclycle view.
This is my xml code of the cardview and my view where the reclyclerview is:
CardView:
This is how it looks in the Ide Android studio:
Layout where the Reclycler view is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="30"
android:textSize="30sp" />
<TextView
android:id="#+id/textIdPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="30"
android:textSize="30sp" />
<TextView
android:id="#+id/textId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="30"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textAmount"
android:padding="8dp"
android:text="ID"
android:textSize="30sp"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textIdPerson"
android:padding="8dp"
android:layout_weight="1"
android:text="UserId"
android:textSize="30sp"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textId"
android:padding="8dp"
android:textSize="30sp"
android:layout_weight="1"
android:text="Amount"
android:gravity="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/recycler_view"
android:nestedScrollingEnabled="false"
tools:listitem="#layout/list_row_main"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="atras"
android:onClick="#{viewmodel::back}"
android:layout_weight="1"
android:layout_marginRight="4dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Siguiente"
android:onClick="#{viewmodel::next}"
android:layout_weight="1"/>
</LinearLayout>
Image:
enter image description here
But when I start the application on the device it looks like this
enter image description here
Your activity_main.xml(or any layout that hosts recyclerview) should look like this.
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center_vertical|center"
android:orientation="horizontal">
<TextView
android:id="#+id/textAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="Amount"
android:textSize="30sp" />
<TextView
android:id="#+id/textIdPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="UserID"
android:textSize="30sp" />
<TextView
android:id="#+id/textId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="Id"
android:textSize="30sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_weight="2"
android:nestedScrollingEnabled="false"
tools:listitem="#layout/list_item" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnAtras"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:text="ATRAS"
/>
<Button
android:id="#+id/btnSignature"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:text="Signature" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
And list_item.xml layout should be something like below:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="60dp"
app:cardCornerRadius="5dp"
app:cardElevation="8dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
app:cardUseCompatPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center|center_vertical"
>
<TextView
android:gravity="center"
android:id="#+id/textAmount"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="match_parent"
android:padding="8dp"
android:text="Amount"
android:textSize="30sp" />
<TextView
android:gravity="center"
android:id="#+id/textIdPerson"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="match_parent"
android:padding="8dp"
android:text="UserId"
android:textSize="30sp" />
<TextView
android:gravity="center"
android:id="#+id/textId"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="match_parent"
android:padding="8dp"
android:text="Id"
android:textSize="30sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Check your adapter class, Layout you designed for adapter class should have width match parent and three different textviews with equal width to hold values.
Make sure the RecyclerView has layout_width also set to match_parent.
I build a layout that overflows the google maps and it look like that: image
so the problem that i get with the layout on the bottom is that i can't center all the conter it stays too much on the left side and i don't know really why.
I want to center the content but mantain the space with each elemnt(i consider the element the background color + the text).
How can i do it?
here is my xml(that contains the map and the layout):
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.afcosta.inesctec.pt.android.MapsActivity" />
<LinearLayout
android:id="#+id/newmarker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:layout_weight="1"
android:text="Legenda"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/rand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFFFFFFF"
android:gravity="center"
android:weightSum="3"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/myPos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#FFFFFFFF"
android:orientation="horizontal">
<Button
android:id="#+id/newmarker_save1"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/red" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Utilizador" />
</LinearLayout>
<LinearLayout
android:id="#+id/allFotos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#FFFFFFFF"
android:orientation="horizontal">
<Button
android:id="#+id/newmarker_save2"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/emerald" />
<TextView
android:id="#+id/Fotos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Fotos" />
</LinearLayout>
<LinearLayout
android:id="#+id/Photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="10dp"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button2"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/yellow" />
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:layout_weight="1"
android:text="Planta" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
thanks!
You have to wrap_content your Button and you TextView, remove android:layout_weight="1" from the textView that lives beside your Button, then finally make sure that every single LinearLayout that wraps your Button and TextView are flagged as android:gravity="center" (this gravity is gonna be applied for its childs)
Also I strongly advise you replacing these linear layouts for Relatives to reduce your UI hierarchy
Try this.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.afcosta.inesctec.pt.android.MapsActivity" />
<LinearLayout
android:id="#+id/newmarker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:layout_weight="1"
android:text="Legenda"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/rand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFFFFFFF"
android:gravity="center"
android:weightSum="3"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/myPos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:layout_weight="1"
android:background="#FFFFFFFF"
android:orientation="horizontal">
<Button
android:id="#+id/newmarker_save1"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/colorAccent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="Utilizador" />
</LinearLayout>
<LinearLayout
android:id="#+id/allFotos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#FFFFFFFF"
android:orientation="horizontal">
<Button
android:id="#+id/newmarker_save2"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/colorAccent" />
<TextView
android:id="#+id/Fotos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="Fotos" />
</LinearLayout>
<LinearLayout
android:id="#+id/Photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="10dp"
android:background="#FFFFFFFF"
android:gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="#+id/button2"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/colorAccent" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="Planta" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I presume that's what you want, right?
I'm a beginner in android development, my project requires me to build a simple UI app using two fragments (home and field). The home will show the starup page with 5 buttons. when we click on these buttons, it will then call field fragment and show fields like:
conductivity:----,height:----
and etc to fill up, like inserting manual data.
my issue here is , the project requires me to use linearlayout in horizontal alignment for the field frag, when i do that and add edit text and text views, its lined in same line as horizontal, but what i need is it to appear one and the other below it: SOme thing like
conductivity(text view): ___________(editText)
[another line]
height(text view):________(editText)
and so on. SOrry this might be a simple issue but i have been stuck on this for 2 days now. Help me
my code for field fragment.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hp1_textView"
android:id="#+id/hp1_textView"
android:textSize="32sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/hp1_textView"
android:layout_centerHorizontal="true"
android:id="#+id/linearLayout">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/conductivity"
android:id="#+id/textView"/>
<EditText android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_weight="1"
android:hint="#string/conductivity_field" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="pH:"
android:id="#+id/textView2" />
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_weight="1"
android:hint="0.-14" />
</LinearLayout>
</RelativeLayout>
THis is how i want it to display
Use this xml in your code as it is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="2">
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Conductivity (uS): "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="745.2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="2">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="pH: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="7.1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="2">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Moisture(%): "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="0-100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="2">
<TextView
android:id="#+id/textVie4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:text="Dissolved oxygen(ppm): "
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="0-100" />
</LinearLayout>
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="5dp"
android:text="Save Log Entry" />
<Button
android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="5dp"
android:text="Show Log Entry" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="3">
<Button
android:id="#+id/btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="5dp"
android:text="Previouse" />
<Button
android:id="#+id/btn4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="5dp"
android:text="Next" />
<Button
android:id="#+id/btn5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:padding="5dp"
android:text="Home" />
</LinearLayout>
</RelativeLayout>
I hope its solve your problem.....
Try below with android:weightSum and LinearLayout with android:orientation
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/hp1_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="hp1"
android:textSize="32sp" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="12">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="conductivity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="conductivity_field" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="pH:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="0.-14" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:orientation="horizontal">
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Moisture(%):"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="0-100" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Disolved Oxygen(ppm)"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="0-100" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="2">
<Button
android:id="#+id/Button11"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:gravity="center"
android:text="Save log entry"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/Button12"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:gravity="center"
android:hint="Show log entries"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/Button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:gravity="center"
android:text="conductivity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/Button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:hint="conductivity_field" />
<Button
android:id="#+id/Button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:hint="conductivity_field" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
If my understanding of your scenario is correct, to display them one below the other as in the image you have supplied, the orientation of the linearLayout must be set to vertical. If you use orientation horizontal the drawing of widgets will falls to the next line, only after it has drawn widgets completely all the way up to the width of your phone( and then it jumped to the next line) .So the LinearLayout should be changed to vertical orientation
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/hp1_textView"
android:layout_centerHorizontal="true"
android:id="#+id/linearLayout">
So, I am creating a workout app and getting problems with imageButtons and text.
Screen-1
content_app_layout_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="hr.app.liftme.liftmehr.AppLayoutMain"
android:orientation="vertical"
tools:showIn="#layout/activity_app_layout_main"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/gornjiLayoutIkone"
android:layout_marginBottom="5dp"
android:layout_marginTop="50dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonVjezbe"
android:background="#drawable/ikona_vjezbe"
android:layout_weight="1"
android:layout_marginRight="8dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonProgramiTreninga"
android:background="#drawable/ikona_programi"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:onClick="ProgramiTreninga"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonPopisTeretana"
android:background="#drawable/ikona_popisteretana"
android:layout_weight="1"
android:layout_marginLeft="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/gornjiLayoutIkone"
android:id="#+id/gornjiLayoutImena"
android:layout_marginBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Vježbe"
android:id="#+id/textViewVjezbe"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Programi \n treninga"
android:id="#+id/textViewProgramiTreninga"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Popis \n teretana"
android:id="#+id/textViewPopisTeretana"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/gornjiLayoutImena"
android:id="#+id/srednjiLayoutIkone"
android:layout_marginBottom="5dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonPrehrana"
android:layout_weight="1"
android:layout_marginRight="8dp"
android:background="#drawable/ikona_prehrana" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonDodaciPrehrani"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#drawable/ikona_dodaciprehrani" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonTrgovineSportskomPrehranom"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:background="#drawable/ikona_popistrgovina" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/srednjiLayoutIkone"
android:layout_marginBottom="5dp"
android:id="#+id/srednjiLayoutImena">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Prehrana"
android:id="#+id/textViewPrehrana"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Dodaci \n prehrani"
android:id="#+id/textViewDodaciPrehrani"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Trgovine \n sportskom \n prehranom"
android:id="#+id/textViewTrgovineSportskomPrehranom"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/srednjiLayoutImena"
android:id="#+id/donjiLayoutIkone"
android:layout_marginBottom="5dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonSavjeti"
android:layout_weight="1"
android:layout_marginRight="8dp"
android:background="#drawable/ikona_savjeti"
android:onClick="Savjeti"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonKalkulatori"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#drawable/ikona_kalkulatori" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonKontakt"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:background="#drawable/ikona_kontakt"
android:onClick="Kontakt"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/donjiLayoutIkone"
android:id="#+id/donjiLayoutImena">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Savjeti"
android:id="#+id/textViewSavjeti"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Kalkulatori"
android:id="#+id/textViewKalkulatori"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Kontakt"
android:id="#+id/textViewKontakt"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</ScrollView>
As you can see, main layout icons are OK, only text is not alligned properly. I don't know should I use layout:margin to align them, I think that won't be good because various screen sizes. Icons look good when there are exacly 3 in a row.
Screen-2
content_programi_treninga.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="hr.app.liftme.liftmehr.ProgramiTreninga"
tools:showIn="#layout/activity_programi_treninga">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonProgramiBodybuilding"
android:background="#drawable/ikona_programi_bodybuilding"
android:layout_weight="1"
android:adjustViewBounds="false"
android:layout_marginRight="15dp"
android:onClick="ProgramiBodybuilding"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="110dp"
android:id="#+id/imageButtonProgramiPowerlifting"
android:background="#drawable/ikona_programi_powerlifting"
android:layout_weight="1"
android:adjustViewBounds="false"
android:layout_marginLeft="15dp"
android:onClick="ProgramiPowerlifting"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:id="#+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Bodybuilding"
android:id="#+id/textViewProgramiBodybuilding"
android:textColor="#000000"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:onClick="ProgramiBodybuilding"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Powerlifting"
android:id="#+id/textView8"
android:textColor="#000000"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:onClick="ProgramiPowerlifting"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout2"
android:gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:id="#+id/linearLayout3">
<ImageButton
android:layout_width="115dp"
android:layout_height="115dp"
android:id="#+id/imageButtonPowerbuilding"
android:background="#drawable/ikona_programi_powerbuilding"
android:layout_weight="0"
android:layout_marginTop="10dp"
android:onClick="ProgramiPowerBuilding"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout3"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Power \nBuilding"
android:id="#+id/textView7"
android:textColor="#000000"
android:gravity="center" />
</LinearLayout>
</RelativeLayout>
As you can see, it doesn't look good with 2 in a row.
I created various icon sizes, from ldpi screen to xxxhdpi screen and when I add them on my layout editor, they are so small so I am using layout:height to correct that. But I don't think that's a good idea because of different screen sizes.
So my question is, what should I do to fix this so it would be perfectly alligned and imageButtons big and in 1:1 ratio?
If you need me to upload some code, just tell me what code and I'll upload it ASAP!
Thanks!
I have a really long layout with tons of layouts etc. How can I wrap it all inside of a scrollview so the user can scroll when it runs out of room? I only want the stuff below "borderSeperator" to be scrollable.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="wrap_content">
<RelativeLayout android:id="#+id/actionbarRelativeLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#drawable/actionbar_gradient">
<ImageButton android:id="#+id/stocktwitsImageButton" android:layout_width="wrap_content" android:background="#drawable/stocktwits" android:layout_height="wrap_content"></ImageButton>
<ImageButton android:layout_width="wrap_content" android:id="#+id/composeImageButton" android:layout_alignParentRight="true" android:layout_height="wrap_content" android:background="#drawable/composebutton"></ImageButton>
</RelativeLayout>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/headerLinearLay"
android:orientation="horizontal" android:background="#e8e8e8" android:padding="8px">
<ImageView
android:id="#+id/avatarImageView"
android:layout_height="48px" android:layout_width="48px"></ImageView>
<LinearLayout android:id="#+id/linearLayout3" android:layout_toRightOf="#+id/avatarImageView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="4dp">
<TextView android:text="TextView" android:textColor="#000000" android:textStyle="bold" android:id="#+id/nameTextView" android:layout_height="wrap_content" android:layout_width="fill_parent"> </TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/usernameTextView" android:textColor="#000000"></TextView>
</LinearLayout>
</RelativeLayout>
<LinearLayout android:layout_height="1dp" android:layout_width="fill_parent" android:id="#+id/borderSeperator" android:background="#c4c4c4"></LinearLayout>
<TextView android:layout_height="wrap_content" android:textSize="24sp" android:layout_width="fill_parent" android:autoLink="web" android:textColor="#000000" android:background="#ffffff" android:padding="8dp" android:id="#+id/bioLabel" android:text="Bio"></TextView>
<TextView android:padding="8dp" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent" android:textColor="#000000" android:background="#ffffff" android:id="#+id/bioTextView"></TextView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="1dp" android:background="#c4c4c4" android:id="#+id/bioSeperator"></LinearLayout>
<TextView android:padding="8dp" android:layout_height="wrap_content" android:textSize="24sp" android:layout_width="fill_parent" android:textColor="#000000" android:autoLink="web" android:background="#ffffff" android:id="#+id/locationLabel" android:text="Location"></TextView>
<TextView android:padding="8dp" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent" android:textColor="#000000" android:background="#ffffff" android:id="#+id/locationTextView"></TextView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="1dp" android:background="#c4c4c4" android:id="#+id/locationSeperator"></LinearLayout>
<TextView android:padding="8dp" android:layout_height="wrap_content" android:textSize="24sp" android:layout_width="fill_parent" android:textColor="#000000" android:autoLink="web" android:background="#ffffff" android:id="#+id/websiteLabel" android:text="Website"></TextView>
<TextView android:padding="8dp" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent" android:textColor="#000000" android:background="#ffffff" android:id="#+id/websiteTextView"></TextView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="1dp" android:background="#c4c4c4" android:id="#+id/websiteSeperator"></LinearLayout>
<LinearLayout android:id="#+id/experienceLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1">
<TextView android:text="Experience" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="#+id/experienceLabel"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="#+id/experienceTextView"></TextView>
</LinearLayout>
<LinearLayout android:id="#+id/assetsLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1">
<TextView android:text="Assets Traded" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="#+id/assetsLabel"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="#+id/assetsTextView"></TextView>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1" android:id="#+id/approachLayout">
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="#+id/approachLabel" android:text="Approach"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="#+id/approachTextView"></TextView>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1" android:id="#+id/riskLayout">
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="#+id/riskLabel" android:text="Risk Profile"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="#+id/riskTextView"></TextView>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1" android:id="#+id/holdingPeriodLayout">
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="#+id/holdingPeriodLabel" android:text="Holding Period"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="#+id/holdingPeriodTextView"></TextView>
</LinearLayout>
</LinearLayout>
Here's a good example of ScrollView It's pretty self explanatory once you look at how they go through it.
The content occurring below your LinearLayout with #+id/borderSeperator (note: which has the </LinearLayout> on the same line) should all be contained inside its own LinearLayout and put inside the ScrollView
In your outer LinearLayout, change its height to wrap_content then simply put it inside of a ScrollView with height and width as fill_parent.
Create a LinearLayout with just a ScrollView in it and put your current top level layout in the scrollview
<LinearLayout>
<ScrollView>
...layoutyou have now
</ScrollView>
</LinearLayout>