I wanted all the elements to scroll, i did not give any values so that it may work on other devices too which are not of the similar size of mine, i tried nearly all the answers and suggestions given over here and failed to see it scroll, i came here as this is my last resort.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".arabicnamazfour">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:weightSum="25">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15"
android:autoSizeTextType="uniform"
android:gravity="center_horizontal"
android:text="رکوع کی دعا"
android:textStyle="bold|italic" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="?android:attr/listDivider"
android:backgroundTint="#32728F"
android:backgroundTintMode="src_over" />
<TextView
android:id="#+id/textView19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7"
android:autoSizeTextType="uniform"
android:text="سُبْحَانَ رَبِّيَ الْعَظِیْمِ ۔ (مسلم) کم از کم تین مرتبہ" />
<TextView
android:id="#+id/textView21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:autoSizeTextType="uniform"
android:gravity="center_horizontal"
android:text="یا دعا پڑھے۔ "
android:textStyle="bold" />
<TextView
android:id="#+id/textView23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:autoSizeTextType="uniform"
android:text="سُبْحَانَکَ اَللّٰہُمَّ رَبَّنَا وَبِحَمْدِکَ اَللّٰہُمَّ اغْفِرْلِیْ ۔ (بخاری و مسلم)" />
<TextView
android:id="#+id/textView25"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7"
android:autoSizeTextType="uniform"
android:gravity="center_horizontal"
android:text="رکوع کے بعد کی دعا"
android:textStyle="bold" />
<TextView
android:id="#+id/textView27"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:autoSizeTextType="uniform"
android:text="رَبَّنَاوَ لَکَ الْحَمْدُ ۔" />
<TextView
android:id="#+id/textView28"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7"
android:autoSizeTextType="uniform"
android:gravity="center_horizontal"
android:text="یا یہ کہے۔"
android:textStyle="bold" />
<TextView
android:id="#+id/textView29"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:autoSizeTextType="uniform"
android:text="رَبَّنَا وَ لَکَ الْحَمْدُ‘ حَمْدًاکَثِیْرًا طَیِّبًا مُّبَارَکًا فِیْہ ۔ (بخاری)" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/fourth" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/fifth" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/sixth" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/seventh" />
</LinearLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoSizeTextType="uniform"
android:backgroundTint="#32728F"
android:gravity="center_horizontal"
android:text="4"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="2">
<ImageView
android:id="#+id/imageView17"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="#drawable/ic_baseline_navigate_before_24" />
<ImageView
android:id="#+id/imageView18"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="#drawable/ic_baseline_navigate_next_24" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
I tried all the answers and everything that i could think of, but it simply wouldnt scroll
Related
I have a pretty strange issue. So, I have a base tab layout which helps navigation between different activities and fragment. However, some of the layouts (esp fragment layouts) seem to be cut off exposing activities in the background.
Any idea why it could be doing this?
Here's the code for the fragment layout:
<?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:background="#color/settingsSeparatorColor"
android:clickable="true"
android:focusable="true"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white">
<ImageButton
android:id="#+id/nav_back_btn"
style="#style/Button.ImageButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#color/transparent"
android:contentDescription="#string/back"
android:tint="#color/black"
app:srcCompat="#drawable/ic_close" />
<TextView
android:id="#+id/profile_edit_button"
style="#style/Body1RegRightBlack"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="#string/profile_edit"
android:gravity="center_vertical"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/profile_pic_container"
layout="#layout/item_profile_pic" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="12dp">
<TextView
android:id="#+id/fullName"
style="#style/Headline3CenterBlack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:background="#android:color/transparent"
android:singleLine="true"
android:textAppearance="#style/TextAppearance.Text.Chronicle"
tools:text="Angela Heely" />
<TextView
android:id="#+id/companyName"
style="#style/Body2RegCenterGrey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/fullName"
android:background="#android:color/transparent"
android:paddingTop="12dp"
android:singleLine="true"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular"
android:textSize="16sp"
tools:text="Cardinal Dev Agency" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="32dp"
android:gravity="center_vertical"
android:weightSum="2">
<TextView
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="#string/home_location"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<TextView
android:id="#+id/home_location"
style="#style/Body1RegRightGrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular"
tools:text="My Home location" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#color/settingsSeparatorColor"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:visibility="gone"
android:weightSum="2">
<TextView
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="#string/push_notifications"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/push_notification_switch"
style="#style/Color1SwitchStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/settingsSeparatorColor" />
<include layout="#layout/item_settings_separator" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/reset_password"
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="#string/reset_password"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<ImageView
android:id="#+id/reset_password_chevron"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="#drawable/ic_baseline_chevron_right_24px"
android:contentDescription="#null"
android:gravity="end"
android:backgroundTint="#color/brownish_grey" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#color/settingsSeparatorColor" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:weightSum="1">
<TextView
android:id="#+id/legal_terms"
style="#style/Body1RegLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="#string/eula"
android:textAppearance="#style/TextAppearance.Text.Roboto.Regular" />
<ImageView
android:id="#+id/legal_terms_chevron"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="#drawable/ic_baseline_chevron_right_24px"
android:contentDescription="#null"
android:gravity="end"
android:backgroundTint="#color/brownish_grey" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/settingsSeparatorColor" />
<include layout="#layout/item_settings_separator" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:background="#color/settingsSeparatorColor"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical">
<TextView
android:id="#+id/optionLogout"
style="#style/Body1RegCenterRed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="#string/sign_out" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:background="#color/transparent"
android:fitsSystemWindows="true"
android:gravity="bottom|center_horizontal">
<TextView
android:id="#+id/optionVersion"
style="#style/Caption1RegCenterGrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Build v. 0.0.1" />
</RelativeLayout>
</LinearLayout>
Here's the code for the tab base container layout: (Please note the actual screen content is displayed in the linearlayout titled : dynamicContent below)
<?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"
android:fitsSystemWindows="true"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/white"
android:id="#+id/bottomNavBar"
android:orientation="horizontal"
android:fitsSystemWindows="true"
android:foregroundGravity="bottom"
android:translationZ="60dp"
android:layout_alignParentBottom="true"
>
<RadioGroup
android:id="#+id/radioGroup1"
android:gravity="center"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
android:text="Matching"
android:layout_weight="1"
android:button="#null"
android:padding="2dp"
android:checked="false"
android:textSize="12sp"
android:drawableTop="#drawable/ic_baseline_chevron_right_24px"
android:textColor="#color/black"
android:id="#+id/matching"/>
<RadioButton
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
android:button="#null"
android:layout_weight="1"
android:padding="2dp"
android:checked="false"
android:textSize="12sp"
android:drawableTop="#drawable/ic_baseline_chevron_right_24px"
android:textColor="#color/black"
android:id="#+id/watchList"
android:text="Watchlist"/>
<RadioButton
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
android:id="#+id/rates"
android:button="#null"
android:paddingTop="5dp"
android:paddingBottom="2dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:layout_weight="1"
android:checked="false"
android:textSize="12sp"
android:drawableTop="#drawable/ic_baseline_chevron_right_24px"
android:textColor="#color/black"
android:text="Rates"/>
<RadioButton
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
android:button="#null"
android:padding="2dp"
android:checked="false"
android:layout_weight="1"
android:textSize="12sp"
android:drawableTop="#drawable/ic_baseline_chevron_right_24px"
android:textColor="#color/black"
android:id="#+id/deals"
android:text="Deals"/>
<RadioButton
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
android:button="#null"
android:padding="2dp"
android:checked="false"
android:layout_weight="1"
android:textSize="12sp"
android:drawableTop="#drawable/ic_baseline_chevron_right_24px"
android:textColor="#color/black"
android:id="#+id/listing"
android:text="Listing"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dynamicContent"
android:background="#color/white"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
I tried many options including fitsystemwindows, commenting out scrollview and other solutions suggested on stackoverflow, but not luck. Any ideas how to go about this one?
Thanks!
Add: android:fillViewport="true" in the scrollview
My goal is to obtain divider lines similar to the ones shown in the following picture:
Goal Picture Divider
I need to place a horizontal and vertical divider between LinearLayout
This is my User Interface 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=".MainActivity"
android:background="#drawable/maingradiant">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اطلاعات ورودی"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="فاکتور"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="هزینه ها"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تسویه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="سامانه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال بار"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am currently using RelativeLayout as the Root Element, and for each row, I am applying a horizontal LinearLayout followed by a vertical LinearLayout.
Based on my current layout, can I receive assistance on how to place the divider lines on my interface, much like the provided picture?
Thank you!
First of all, I would recomend you to use RecyclerView with GridLayoutManager for this purpose. creating recyclerview with gridmanager
but if you want stick with current design, you add line by creating a View in xml
For Vertical line
<View
android:layout_width="2dp" //thickness
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
For Horizontal line
<View
android:layout_width="match_parent"
android:layout_height="2dp"//thickness
android:background="#color/colorPrimary" />
for shading colors you should look for something like Gradient in android. How ro create Gradient in android
code looks like this.
<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:background="#drawable/maingradiant"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اطلاعات ورودی"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="فاکتور"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="هزینه ها"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تسویه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="سامانه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال بار"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Happy coding!!
I am not sure whether its possible to do this, but look at this switch button:
Switch button location
So what I am trying to do is to move it at the exact center, where it should be on the red square location: Center location
Just to let you know that I have tried:
android:gravity="center" // didn't work
android:layout_gravity="center"// didn't work
android:foregroundGravity="center"// didn't work
this is my full xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="25">
</android.support.constraint.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.37">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="30"
app:srcCompat="#drawable/ubersign" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40"
android:text="Driver"
android:textAlignment="center" />
<Switch
android:id="#+id/switch3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:onClick="switchOnOf" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40"
android:text="Rider"
android:textAlignment="center" />
</LinearLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
android:text="Get Started" />
</LinearLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="25">
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
So is there any possible way to do what I want?
Replace LinearLayout with RelativeLayout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_toLeftOf="#+id/switch3"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Driver"
android:textAlignment="center" />
<Switch
android:id="#+id/switch3"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:onClick="switchOnOf" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/switch3"
android:text="Rider"
android:textAlignment="center" />
</RelativeLayout>
Or you can keep the LinearLayour and do the following:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="Driver"
android:textAlignment="center" />
<Switch
android:id="#+id/switch3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="switchOnOf" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="Rider"
android:textAlignment="center" />
</LinearLayout>
Just change the value of android:layout_weight="20" to android:layout_weight="10"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40"
android:text="Driver"
android:textAlignment="center" />
<Switch
android:id="#+id/switch3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="switchOnOf" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="40"
android:text="Rider"
android:textAlignment="center" />
</LinearLayout>
Here is the output of my code. I cannot get all views aligned in each ListView item. I already used layout_weight for each view and also set the layout_width to 0sp. Really curious about why it cannot work. Hope to get some solutions. Thank you!
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="95sp">
<ImageView
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/download"
android:layout_weight="1"
android:layout_marginLeft="12sp"
android:scaleType="fitCenter"
android:adjustViewBounds="false"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical"
android:layout_marginLeft="12sp">
<TextView
android:id="#+id/name"
android:text="name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"/>
<TextView
android:id="#+id/new_age"
android:text="New Age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"/>
<TextView
android:id="#+id/email"
android:text="Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"/>
<TextView
android:id="#+id/phone"
android:text="Phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"/>
</LinearLayout>
<TextView
android:id="#+id/countdown"
android:text="Tomorrow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="16sp"
android:textSize="16sp"/>
...
</LinearLayout>
Use this :
<?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="95dp"
android:weightSum="4"
android:orientation="horizontal">
<ImageView
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="12sp"
android:layout_weight="1"
android:adjustViewBounds="false"
android:scaleType="fitCenter"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="12sp"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/new_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Age"
android:textSize="16sp" />
<TextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="16sp" />
<TextView
android:id="#+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Phone"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:gravity="center"
android:text="Tomorrow"
android:textSize="16sp" />
<TextView
android:id="#+id/daysago"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:gravity="center"
android:text="4days ago"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
You need to add layout_weightSum in your parent layout -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="95dp"
android:weightSum="4"
android:orientation="horizontal">
<ImageView
android:id="#+id/image"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="12sp"
android:layout_weight="1"
android:adjustViewBounds="false"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="12sp"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="name"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/new_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="New Age"
android:textSize="16sp" />
<TextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Email"
android:textSize="16sp" />
<TextView
android:id="#+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Phone"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:gravity="center"
tools:text="Tomorrow"
android:textSize="16sp" />
<TextView
android:id="#+id/daysago"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:gravity="center"
tools:text="4 days ago"
android:textSize="16sp" />
</LinearLayout>
You need to then equally distribute the weight by using android:layout_weight="1" on each of the child layouts.
Let me know if you need more help.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/progressBarLL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/app_background_color"
android:gravity="center"
android:visibility="visible">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollableContent"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dp">
<LinearLayout
android:id="#+id/navigationControlLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="4">
<ImageView
android:id="#+id/previousPageImageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/previous_page_darken" />
<TextView
android:id="#+id/dealsPageNumberStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="1/50"
android:textSize="#dimen/text_size_medium" />
<ImageView
android:id="#+id/nextPageImageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/next_page_darken" />
</LinearLayout>
<LinearLayout
android:id="#+id/dealsFragmentLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/margin_large"
android:layout_marginLeft="#dimen/margin_normal"
android:layout_marginRight="#dimen/margin_normal"
android:layout_marginTop="4dp"
android:background="#drawable/background_with_shadow"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:orientation="horizontal"
android:paddingTop="0dp">
<ImageView
android:id="#+id/dealsFragmentImage"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="2"
android:background="#android:color/transparent"
android:minHeight="#dimen/min_image_height"
android:padding="5dp"
android:src="#drawable/test_logo" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4.00"
android:orientation="vertical"
android:padding="#dimen/padding_normal">
<TextView
android:id="#+id/dealsFragmentTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="This text is intentionally made larger to go beyound 2 lines"
android:textSize="#dimen/text_size_medium"
android:padding="#dimen/padding_normal" />
<TextView
android:id="#+id/dealsTimeSubmitted"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="2"
android:text="about an hour ago "
android:textColor="#color/light_grey"
android:textSize="#dimen/text_size_small"
android:padding="#dimen/padding_normal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal"
android:padding="#dimen/padding_normal">
<TextView
android:id="#+id/dealsCurrentPrice"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:padding="4dp"
android:text="Rs. 135"
android:textColor="#color/deals_blue"
android:textSize="#dimen/text_size_large"
android:textStyle="bold" />
<TextView
android:id="#+id/dealsOffPercent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:padding="4dp"
android:text="(90% off)"
android:textColor="#color/deals_blue"
android:textSize="#dimen/text_size_medium" />
<TextView
android:id="#+id/dealsOriginalPrice"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:padding="4dp"
android:text="1235698"
android:singleLine="true"
android:textColor="#color/light_grey"
android:textSize="#dimen/text_size_small" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:paddingLeft="4dp"
android:text="#string/submitted_by"
android:textColor="#color/light_text"
android:textSize="#dimen/text_size_small" />
<TextView
android:id="#+id/dealsFragmentSubmittedBy"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:text=" aniket007"
android:textColor="#color/deals_blue"
android:textSize="#dimen/text_size_small" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left|center"
android:text=" in "
android:textColor="#color/light_text"
android:textSize="#dimen/text_size_small" />
<TextView
android:id="#+id/dealsCategory"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ellipsize="end"
android:gravity="left|center"
android:maxLines="1"
android:paddingRight="4dp"
android:text="Mobiles and Mobile Accessories"
android:textColor="#color/deals_blue"
android:textSize="#dimen/text_size_small" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/item_separator"
android:layout_marginLeft="#dimen/margin_normal"
android:layout_marginRight="#dimen/margin_normal" />
<WebView
android:id="#+id/dealDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:contentDescription="#string/top_deals"
android:textSize="#dimen/text_size_medium" />
<include
layout="#layout/list_item_deal_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<!--<LinearLayout
android:id="#+id/dealsFragmentCommentLinearLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#color/deals_footer"
android:orientation="horizontal">
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#color/flat_grey" />
<ImageView
android:id="#+id/dealsFragmentLikeImage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:src="#drawable/comment_icon" />
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#color/flat_grey" />
<ImageView
android:id="#+id/dealsFragmentDislikeImage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:src="#drawable/comment_icon" />
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#color/flat_grey" />
<ImageView
android:id="#+id/dealsFragmentShareImage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/popularity_icon" />
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#color/flat_grey" />
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="#+id/viewCommentsButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:minHeight="#dimen/fb_button_min_height"
android:text="#string/viewComments"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_medium"
fbutton:buttonColor="#color/fbutton_default_color"
fbutton:cornerRadius="5dp"
fbutton:shadowColor="#color/fbutton_default_shadow_color"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="2dp" />-->
<info.hoang8f.widget.FButton
android:id="#+id/buyNowButtonPlaceHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:minHeight="#dimen/fb_button_min_height"
android:text="#string/buy_now"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_medium"
android:visibility="invisible"
fbutton:buttonColor="#color/fbutton_default_color"
fbutton:cornerRadius="5dp"
fbutton:shadowColor="#color/fbutton_default_shadow_color"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="2dp" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ccffffff">
<info.hoang8f.widget.FButton
android:id="#+id/buyNowButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:minHeight="#dimen/fb_button_min_height"
android:minWidth="#dimen/buy_now_button_width"
android:text="#string/buy_now"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_medium"
fbutton:buttonColor="#color/fbutton_default_color"
fbutton:cornerRadius="5dp"
fbutton:shadowColor="#color/fbutton_default_shadow_color"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="2dp" />
</RelativeLayout>
</RelativeLayout>
I am using WebView inside ScrollView and it does work correctly on android versions higher than 16. But on lower version page do not get scrolled when scrolled on webview. Page does get scrolled from right side of page. Links too do not open when clicked on left side but does open from right side.
found few solutions like android:hardwareAccelerated="true", but not working.