In my Android application, I have an ExpandableListView with each group having some childs, which contains a checkbox. I'm having trouble in setting the position of the checkboxes.
Curent, my checkbox on the right of the Childs When run on phone, even though it's on the left in Childs.XML, now I want to move the checkbox to the left of the Childs.
Guide me. plsss.. Thanks all so much.
My main XML:
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".discover.DiscoverFilterFragment">
<ProgressBar
android:id="#+id/filter_progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="666dp"
android:orientation="vertical"
android:padding="0dp"
android:id="#+id/expLayout">
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/expFilter"
android:groupIndicator="#drawable/expand_icon"
android:layoutDirection="rtl"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
/>
</LinearLayout>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="6dp"
android:background="#drawable/btn_view_attachments">
<Button
android:id="#+id/btnApply"
android:layout_width="328dp"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:backgroundTint="#00FFFFFF"
android:text="Apply"
android:textColor="#FFFFFF"
android:textSize="16sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
</RelativeLayout>
My Parent XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/titleLayout"
android:orientation="horizontal">
<TextView
android:id="#+id/listTitle"
android:text="#string/title"
android:textSize="22sp"
android:textAppearance="#style/TextAppearance.AppCompat.Medium.Inverse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:layout_marginStart="25dp"
android:paddingTop="10dp"
android:textColor="#android:color/black"/>
</LinearLayout>
My Child XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/itemLayout"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants">
<CheckBox
android:id="#+id/itemsCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:focusable="false"
android:clickable="false"
style="#android:style/Widget.CompoundButton.RadioButton"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="16dp"
android:id="#+id/listItem"
android:layoutDirection="ltr"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
tools:text="Item 0" />
</LinearLayout>
Related
I want the ImageView keep its aspect ratio with layout_height=match_parent
but I don't know why this happen ?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="#drawable/bob" />
<TextView
android:gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bob" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/bob" />
<TextView
android:gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bob" />
</LinearLayout>
</LinearLayout>
Use for this to set in full image view scaletype=fitxy
This is my grid item xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimaryDark"
android:id="#+id/griditem">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="15sp"
android:padding="5dp"
android:id="#+id/name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="15sp"
android:padding="5dp"
android:id="#+id/date"/>
</LinearLayout>
recyclerview in fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:foregroundGravity="center"
android:id="#+id/recentView"/>
</LinearLayout>
Recycleview config in kotlin:
recentView.layoutManager = GridLayoutManager(context,2)
My Layout output:
I dont want the extra space above and below my imageview
try this
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/ic_account_circle"/>
Use android:scaleType="fitXY" in ImageView
My activity has 3 elements. Linearlayout, Gridview and the Linearlayout. See picture. How to make Gridview items is completely visible even if there is a scroll on all screens? p.s. Sorry for my English.
Well use this code for such a layout design...
<?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:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/layoutTopLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/btn_br_color"
android:gravity="center"
android:layout_alignParentTop="true"
android:padding="3dp">
<TextView
android:id="#+id/primiumGameNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="4"
android:text="Layout1"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<GridView
android:id="#+id/gridViewID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_below="#+id/layoutTopLay"
android:layout_above="#+id/layoutBottomLay"
android:paddingRight="5dp"
android:paddingTop="3dp" />
<LinearLayout
android:id="#+id/layoutBottomLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/btn_br_color"
android:gravity="center"
android:layout_alignParentBottom="true"
android:padding="3dp">
<TextView
android:id="#+id/layoutBottomText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:gravity="center"
android:maxLines="24"
android:text="Layout2"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
Another way how to do it is to use layout_weight attribute:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/holo_blue_dark"
/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:background="#android:color/white"
>
<!-- put content here -->
</GridLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/holo_blue_dark"
/>
</LinearLayout>
Here's my MainActivity.xml where I'm using LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffe6cc"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zorgan.app.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#333"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="116dp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="#drawable/front"
android:contentDescription="#string/front_desc" />
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
tools:layout_editor_absoluteY="496dp" />
</LinearLayout>
How would I nest these 3 views into one view, so they all sit vertically central?
To vertically center the child views, give android:gravity="center_vertical" to the parent view. In your case, for the LinearLayout.
here try this layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffe6cc"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zorgan.app.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#333"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="116dp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="#drawable/front"
android:contentDescription="#string/front_desc" />
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="496dp" />
</LinearLayout>
in this android:gravity="center" is the key parameter.
Replace your code with,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffe6cc"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#333"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="116dp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_vertical|center_horizontal"
app:srcCompat="#drawable/front"
android:contentDescription="front_desc" />
<Button
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" />
</LinearLayout>
It is tested and working.
I have RelativeLayout inside SrcollView. That ScrollView will be an child of LinearLayout. In RelativeLayout I added views programmatically. But ScrollView is not scrolling.
startActivityCenterLayout - place between AutocompleteTextView's container and Button's container.
How I can resolve it?
<?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:id="#+id/startActivityRootLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:background="#color/dark_cyan"
tools:context="com.geodevteam.geopay.project.activity.StartActivity">
<LinearLayout
android:orientation="vertical"
android:id="#+id/startActivityTopLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/dark_cyan">
<ImageView
android:id="#+id/startActivityLogoImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="#mipmap/ico"/>
<TextView
android:id="#+id/startActivityLogoTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
style="#style/ApplicationNameTextView"
android:text="#string/application_title"/>
<AutoCompleteTextView
android:id="#+id/startActivityAutocompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
style="#style/AutocompleteTextViewTextColor"
android:hint="#string/start_to_input_name"/>
</LinearLayout>
<LinearLayout
android:id="#+id/startActivityCenterLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/startActivityTopLayout"
android:paddingBottom="10dp"
android:background="#color/dark_cyan">
<ScrollView
android:id="#+id/startActivityCenterLayoutScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/cardsRootLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="#+id/startActivityBottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/dark_cyan">
<Button
android:id="#+id/startActivitySocialsButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/login_by_mail_button"
style="#style/LoginByMailButton"
android:text="#string/login_sign_using_social" />
<Button
android:id="#+id/startActivityEmailButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/login_by_mail_button"
style="#style/LoginByMailButton"
android:text="#string/login_using_mail" />
</LinearLayout>
</RelativeLayout>
The layout is scrollable if necessary, so if you didn't put anything inside the Relative Layout, you aren't able to scroll.
This is Because hight of your ScrollView is 0dp. And Regarding that weight you have given to ScrollViewis work only if you have given weightSum to parent LinearLayout.
Eighter you give weightSum to LinrearLayout or Change Hight of ScrollView to match_parent.
Happy Coding.
Now scrollview is working. Code down below
<?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:id="#+id/startActivityRootLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:background="#color/dark_cyan"
tools:context="com.geodevteam.geopay.project.activity.StartActivity">
<LinearLayout
android:orientation="vertical"
android:id="#+id/startActivityTopLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/dark_cyan">
<ImageView
android:id="#+id/startActivityLogoImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:src="#mipmap/ico"/>
<TextView
android:id="#+id/startActivityLogoTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
style="#style/ApplicationNameTextView"
android:text="#string/application_title"/>
<AutoCompleteTextView
android:id="#+id/startActivityAutocompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
style="#style/AutocompleteTextViewTextColor"
android:hint="#string/start_to_input_name"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="#+id/startActivityBottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentBottom="true"
android:background="#color/dark_cyan">
<Button
android:id="#+id/startActivitySocialsButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/login_by_mail_button"
style="#style/LoginByMailButton"
android:text="#string/login_sign_using_social" />
<Button
android:id="#+id/startActivityEmailButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/login_by_mail_button"
style="#style/LoginByMailButton"
android:text="#string/login_using_mail" />
</LinearLayout>
<LinearLayout
android:id="#+id/startActivityCenterLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/startActivityBottomLayout"
android:layout_below="#id/startActivityTopLayout"
android:background="#color/dark_cyan">
<ScrollView
android:id="#+id/startActivityCenterLayoutScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/cardsRootLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>