I have no idea how to put part of my textview and buttons on the bottom of the page. I tried to gravity bottom, etc.. but it didnt work.
<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"
tools:context="com.example.tiagosilva.amob_android.HomeFragment"
android:background="#color/AMOB_gray">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Company"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="#string/welcomeAmobHome"
android:textColor="#android:color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Follow us on our Social Networks"
android:textSize="20dp"
android:textColor="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5">
<Button
android:id="#+id/btn_facebook"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="54dp"
android:background="#drawable/facebook_icon"
android:layout_margin="10dp"/>
<Button
android:id="#+id/btn_twitter"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="55dp"
android:background="#drawable/twitter_icon"
android:layout_margin="10dp"/>
<Button
android:id="#+id/btn_youtube"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:background="#drawable/instagram_icon"
android:layout_margin="10dp"/>
<Button
android:id="#+id/btn_instagram"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:background="#drawable/youtube_icon"
android:layout_margin="10dp"/>
<Button
android:id="#+id/btn_flickr"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="49dp"
android:background="#drawable/flikr_icon"
android:layout_margin="10dp"/>
</LinearLayout>
</LinearLayout>
I only want to dock the buttons and the textview that says "Follow us on our Social Networks".
enter image description here
Something like this can help you,
<?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"
tools:context="com.example.tiagosilva.amob_android.HomeFragment"
android:background="#color/AMOB_gray">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Company"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="#string/welcomeAmobHome"
android:textColor="#android:color/white"
android:textSize="14sp"
android:layout_below="#id/textView10"/>
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Follow us on our Social Networks"
android:textColor="#android:color/white"
android:textSize="20dp"
android:layout_below="#id/textView11"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5"
android:layout_below="#id/textView12"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/btn_facebook"
android:layout_width="0dp"
android:layout_height="54dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/facebook_icon"/>
<Button
android:id="#+id/btn_twitter"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/twitter_icon"/>
<Button
android:id="#+id/btn_youtube"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/instagram_icon"/>
<Button
android:id="#+id/btn_instagram"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/youtube_icon"/>
<Button
android:id="#+id/btn_flickr"
android:layout_width="0dp"
android:layout_height="49dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/flikr_icon"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Related
I am getting the json data lengthy and i have to scroll the view to get the buttons below. How Can I make the button display. When I am trying to give scrollview its not working.
I have changed your layout structure. I have resolved your problem by adding Relative layout and by giving fix height to scrollview as your scenario is very clear that you want all buttons visible while only scrolling question's content. So here is your solution just copy and paste this xml into your xml. :)
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3D996C">
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/timer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3D996C"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<ImageButton
android:id="#+id/play_timmer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:backgroundTint="#color/cardview_shadow_end_color"
android:src="#drawable/ic_play">
</ImageButton>
<TextView
android:id="#+id/timmer_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/_2_30_30"
android:textAlignment="center"
android:textColor="#FFF"
android:textSize="24sp">
</TextView>
<ImageButton
android:id="#+id/navigation_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:backgroundTint="#color/cardview_shadow_end_color"
android:src="#drawable/ic_stop">
</ImageButton>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_previos_skip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/timer_layout"
android:weightSum="3">
<Button
android:id="#+id/previous_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#3D996C"
android:text="Previous"
android:textColor="#FFF">
</Button>
<TextView
android:id="#+id/score_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="2/200"
android:textSize="24sp"
android:textStyle="bold">
</TextView>
<Button
android:id="#+id/skip_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#3D996C"
android:text="SKIP"
android:textColor="#FFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/question_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_below="#+id/layout_previos_skip"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:id="#+id/questions_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Question no 1"
android:textSize="18sp"
android:textStyle="bold">
</TextView>
</ScrollView>
</LinearLayout>
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone">
</ProgressBar>
<LinearLayout
android:id="#+id/radioGroup"
android:layout_below="#+id/question_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
<RadioGroup
android:id="#+id/answers_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<RadioButton
android:id="#+id/answer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ANSWER 1">
</RadioButton>
<RadioButton
android:id="#+id/answer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ANSWER 2">
</RadioButton>
<RadioButton
android:id="#+id/answer3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ANSWER 3">
</RadioButton>
<RadioButton
android:id="#+id/answer4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ANSWER 4">
</RadioButton>
</RadioGroup>
</LinearLayout>
<Button
android:id="#+id/submit_and_procced"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:background="#ed9c28"
android:padding="20dp"
android:text="SUBMIT AND PROCEED"
android:textColor="#6F0606"
android:layout_below="#+id/radioGroup"
>
</Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical"
android:layout_alignParentBottom="true"
>
<LinearLayout
android:id="#+id/last_page"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/skipped"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ed9c28"
android:text="SKIPPED"
android:textColor="#831212"
android:textSize="18sp">
</Button>
<Button
android:id="#+id/answered"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#3D996C"
android:text="ANSWERED"
android:textColor="#00695C"
android:textSize="18sp">
</Button>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I am working on this project and I am designing the layout specifically in adding a product that deals with multiple cards.
The android studio that I am working on has an SDKVersion of 28. I have tried checking out some answers from other posts but none of them helped. In addition, I saw some tutorials on YouTube that you have to use an itemAdapter but it will only show you cards with same information. Mine is different.
The picture below that I designed is the one that I want. However, after executing the my code below, it is only showing the first CardView and nothing about "Discount" CardView when I scroll down on my app which shows on the second picture.
activity_add_product.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".AddProductActivity"
android:orientation="vertical"
android:background="#color/colorWhiteBG">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/cv_prod"
android:layout_width="600dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/colorWhite"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Name"
android:textStyle="bold"
android:textColor="#color/colorDarkText"
android:textSize="#dimen/card_title"/>
<EditText
android:id="#+id/editTextProdName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textAutoComplete"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Category"
android:textColor="#color/colorDarkText"
android:textSize="#dimen/card_title"
android:textStyle="bold"/>
<Spinner
android:id="#+id/spinnerCategory"
android:layout_width="match_parent"
android:layout_height="50dp"
android:entries="#array/prodcategorylist"
android:padding="5dp"></Spinner>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:text="This item is available for sale."/>
</LinearLayout>
<LinearLayout
android:id="#+id/conditionlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Condition"
android:textStyle="bold"
android:textSize="#dimen/card_title"
android:textColor="#color/colorDarkText"/>
<Spinner
android:id="#+id/spinnerCondition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/conditionlist"
android:padding="5dp"></Spinner>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Item Count"
android:textSize="#dimen/card_title"
android:textColor="#color/colorDarkText"
android:textStyle="bold"/>
<EditText
android:id="#+id/editTextConditionCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:inputType="number"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity of an item according to it's condition."
android:textSize="6dp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/expirationdatelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Expiration Date"
android:textStyle="bold"
android:textSize="#dimen/card_title"
android:textColor="#color/colorDarkText"/>
<EditText
android:id="#+id/spinnerExpiration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="date"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Item Count"
android:textSize="#dimen/card_title"
android:textColor="#color/colorDarkText"
android:textStyle="bold"/>
<EditText
android:id="#+id/editTextExpCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:inputType="number"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity of an item according to it's expiration date."
android:textSize="6dp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<ImageView
android:id="#+id/imageaddBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_circle_black_24dp"
android:tint="#color/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="ADD EXPIRATION DATE"
android:textColor="#color/colorDarkText" />
</LinearLayout>
<LinearLayout
android:id="#+id/soldbyandunitlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sold by"
android:textColor="#color/colorDarkText"
android:textSize="#dimen/card_title"
android:textStyle="bold"
android:layout_gravity="center"/>
<RadioGroup
android:id="#+id/radioGroupSoldBy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="center"
android:paddingLeft="10dp">
<RadioButton
android:id="#+id/radioBtnEach"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/stringEach"
android:buttonTint="#color/colorPrimary"/>
<RadioButton
android:id="#+id/radioBtnWeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/stringWeight"
android:buttonTint="#color/colorPrimary"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Unit"
android:textColor="#color/colorDarkText"
android:textSize="#dimen/card_title"
android:textStyle="bold"/>
<Spinner
android:id="#+id/spinnerSoldbyUnit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/unitlist"
android:padding="5dp"></Spinner>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/pricelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price"
android:textStyle="bold"
android:textSize="#dimen/card_title"
android:textColor="#color/colorDarkText"/>
<EditText
android:id="#+id/editTextPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="0.00"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingLeft="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="QR Code"
android:textSize="#dimen/card_title"
android:textColor="#color/colorDarkText"
android:textStyle="bold"/>
<EditText
android:id="#+id/editTextQRCode1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:inputType="text"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/cv_discounts"
android:layout_width="600dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/colorWhite"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Discounts"
android:textSize="#dimen/card_title_name"
android:textColor="#color/colorDarkText"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="In Stock"
android:textStyle="bold"
android:textColor="#color/colorDarkText"
android:textSize="#dimen/card_title" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ROP"
android:textColor="#color/colorDarkText"
android:textSize="#dimen/card_title"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextProdInStock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:hint="0"/>
<EditText
android:id="#+id/editTextProdVal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:hint="0"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</ScrollView>
</LinearLayout>
I'm designing a UI using android studio and my problem is that I see a free space on the design editor and the emulator but not on the device .
here is how it looks on the design editor and the emulator
enter image description here
and here is how it looks on the device
enter image description here
and here is the XML code :
<?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"
tools:context="com.example.MyPfe.ClientInterface">
<LinearLayout
android:id="#+id/global_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#id/Butt_layout"
android:weightSum="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:weightSum="1"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="10dp"
android:src="#drawable/ic_car" />
<Button
android:layout_width="200dp"
android:layout_height="30dp"
android:textAlignment="center"
android:text="Document à transmettre"
android:textSize="12dp"
android:textColor="#color/backgroundcolor"
android:layout_marginTop="5dp"
android:background="#color/sogreen"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/textcolor"
android:text="CONTRAT AUTO N°"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="nome et prenom"
android:textColor="#color/textcolor"/>
</LinearLayout>
<View
android:layout_marginTop="10dp"
android:layout_width="250dp"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/textcolor"
android:text="Début du contrat le"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="Échéance le"
android:textColor="#color/textcolor"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:id="#+id/cons_cont_lin"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Consulter mon contrat"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Modifier mon contrat"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Suivre un sinistre"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Déclarer un sininstre"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/Butt_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/bt_depannage"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/sogreen"
android:text="URGENCE ET DÉPANNAGE"
android:textAlignment="center"
android:textColor="#color/backgroundcolor"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
There is no issue with your rendering. The device resolution in the emulator and designer view is higher than your real device. Try setting the designer or your emulator to the same width and height as your device and you will see its all the same.
From what I see, the lower part containing the icons is aligned to the baseline/bottom etc. of the parent container or something like that. I think your device is 4.5" or 5" screen while your designer and your emulator is a 6" screen.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/colorSlate"
android:orientation="vertical">
<TextView
android:id="#+id/hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#5d737e"
android:padding="20dp"
android:text="₹ 250.00"
android:textColor="#color/colorWhite" />
</LinearLayout>
<LinearLayout
android:id="#+id/world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/colorTurquoiseBlue"
android:onClick="#{()->upgradeViewModel.gotoPremimum()}"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:fontFamily="sans-serif-medium"
android:letterSpacing="-0.03"
android:text="Go premium"
android:textColor="#color/colorWhite"
android:textSize="14.4sp"
android:textStyle="normal" />
<ImageView
android:layout_width="8dp"
android:layout_height="14dp"
android:layout_gravity="center"
android:layout_weight=".5"
app:srcCompat="#drawable/ic_arrow_white"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
This is my xml i am trying to display text horizontally in first linear-layout but when i try to insert another text-view below text-view inside linear-layout i am my first linear-layout get increase not fit with second layout please suggest me how to achieve this i want set text below 200 in given screen
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#5d737e"
android:paddingStart="20dp"
android:paddingTop="10dp"
android:layout_weight="0.5"
android:textSize="15sp"
android:text="₹ 250.00"
/>
<TextView
android:id="#+id/hello1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#5d737e"
android:paddingStart="20dp"
android:paddingBottom="10dp"
android:textSize="15sp"
android:layout_weight="0.5"
android:text="₹ 250.00"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:onClick="#{()->upgradeViewModel.gotoPremimum()}"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:fontFamily="sans-serif-medium"
android:letterSpacing="-0.03"
android:text="Go premium"
android:textSize="14.4sp"
android:textStyle="normal" />
<ImageView
android:layout_width="8dp"
android:layout_height="14dp"
android:layout_gravity="center"
android:layout_weight=".5"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Use the layout below . I have changes some attributes to default you can reset them as per your requirement.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/blue_end"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="₹ 250.00"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/subscription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="4dp"
android:text="Subscription"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/transparent_black"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:fontFamily="sans-serif-medium"
android:letterSpacing="-0.03"
android:text="Go premium"
android:textSize="14.4sp"
android:textStyle="normal" />
<ImageView
android:layout_width="8dp"
android:layout_height="14dp"
android:layout_gravity="center"
android:layout_weight=".5"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:padding="10dp"
android:gravity="center"
android:layout_gravity="center"
android:background="#5d737e"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="₹ 250.00"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/hello2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Yearly Subscription"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/world"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="#{()->upgradeViewModel.gotoPremimum()}"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:fontFamily="sans-serif-medium"
android:letterSpacing="-0.03"
android:text="Go premium"
android:textColor="#000"
android:textSize="14.4sp"
android:textStyle="normal" />
<ImageView
android:layout_width="8dp"
android:layout_height="14dp"
android:layout_gravity="center"
android:layout_weight=".5"
app:srcCompat="#drawable/ic_arrow_white"
/>
</LinearLayout>
</LinearLayout>
try this. :)
I'm making a list of schedules. I use weightsum and layout_weight but the fields are too much expanded. How to fix it. Here is the code i=of list item There is a big space between from-to to no of seats.
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#layout/layout_bg_fav_bus_left"
android:layout_weight="7"
android:weightSum="7"
android:gravity="left"
android:layout_gravity="left">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:orientation="horizontal"
android:layout_weight="3">
<TextView
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#color/genaral_blue"
android:id="#+id/txt_route"
android:text="Route"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_avail_seats"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="2dp"
android:textColor="#color/genaral_blue"
android:text="Available"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="2">
<ImageView
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:src="#drawable/booking"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
android:textColor="#color/genaral_blue"
android:textSize="15dp"
android:text="Book Your Seat"
android:gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:weightSum="3"
android:background="#layout/layout_bg_fav_bus_right"
android:orientation="vertical"
android:layout_gravity="right"
android:gravity="right">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="5"
android:id="#+id/txt_time_now"
android:textColor="#color/alice_blue"
android:textSize="45dp"
android:textAlignment="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginBottom="3dp"
android:text="20"
android:id="#+id/txt_time_next1"
android:textColor="#color/alice_blue"
android:textSize="15dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30"
android:layout_marginBottom="3dp"
android:textColor="#color/alice_blue"
android:id="#+id/txt_time_next2"
android:textSize="15dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
</LinearLayout>
</LinearLayout>