I am using grid view to display images in my app and I am using CardView for parent element.
I want the CardView to have some space from the beggining of the page and between each CardView so I am setting layout_margin to be 5dp.
I also want to have some space between the image and the beggining of the CardView so I put contentPadding to be 10dp.
The result though is not what I want. It seems that the layout_margin is pushing the image itself and the padding for the right side is not 10dp as I want but 10dp - 5dp and I really have no clue how to fix that
Here is visual examples:
And this is the result I get:
You can see the right side of the CardView and how the image is not properly centered.
Thank you for your help!
Edit:
ImageViewStyle:
<style name="ImageViewStyle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">#dimen/card_view_image_view_height</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_alignParentTop">true</item>
<item name="android:scaleType">centerCrop</item>
</style>
Try this:
<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_margin="5dp"
app:cardCornerRadius="2dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/image"/>
</android.support.v7.widget.CardView>
Related
I'm creating an Android app with a BottomNavigationView and for some reason there is blank space on either side so it doesn't fill the whole width of the screen. It's not padding, because I removed the padding and I can see the shadow of the bottom view separating the blank area from the space above. Why are my four menu items not filling the entire width of the screen?
It looks good when I have three or five items so is this just a limitation of dividing the screen space into even numbers?
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/colorNavTint"
app:itemTextColor="#color/colorNavText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/navigation" />
navigation Menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_discover"
android:icon="#drawable/ic_discover"
android:title="Discover"/>
<item
android:id="#+id/navigation_search"
android:icon="#drawable/ic_search"
android:title="Search"/>
<item
android:id="#+id/navigation_messages"
android:icon="#drawable/ic_messages"
android:title="Messages"/>
<item
android:id="#+id/navigation_orders"
android:icon="#drawable/ic_orders"
android:title="Orders"/>
</menu>
and the parent ConstraintLayout:
<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=".MainActivity">
I want to implement a ViewPager having angled rectangle as background as shown in the image. I have tried to get it done by setting xml as background. But it only displays properly if we give image in that xml itself and if I try to manage it runtime then it is not taking that angled background.
This is the drawable I have attached to custom viewpager layout
<item android:top="300dp"
android:bottom="-300dp"
android:left="0dp"
android:right="-300dp">
<rotate
android:fromDegrees="-10"
android:pivotX="0%"
android:pivotY="100%">
<shape
android:shape="rectangle">
<solid
android:color="#color/white"/>
</shape>
</rotate>
AND this is the custom viewpager layout
<?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">
<RelativeLayout
android:id="#+id/rl_image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#drawable/custom_imageview">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/rl_image"
android:layout_marginLeft="20dp"
android:layout_marginTop="-60dp">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/fashion1"
app:civ_border_color="#FFF"
app:civ_border_width="1dp" />
</RelativeLayout>
</RelativeLayout>
This is how it should display
Can anyone please tell me how to do it?
If you need to learn how to create a diagonal cut you could have a look at this tutorial:
https://medium.com/#adinugroho/create-diagonal-cut-view-in-android-5a376eca6a1c
If you need a library to do it for you then have a look at this library:
https://github.com/florent37/DiagonalLayout
This is how it should display
checked this link.
based on above link i guess as page swipes you want change background.
solution :
use constraint_layout or frame_layout.
add view pager as match_parent in height and width.
angle view use it and view on top of view_pager.
suggestion : use constraint layout.
note : above solution will not change view_pager dimensions (dont change it since view is complex, if you change behaviour unpredictable). Only you end up with place custom view on top of pager.
How can i display icons along with text in Bottom navigation of Android.
Many thanks!
click here to view the image
That looks like a CardView wrapping a BottomNavigationView.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="24dp"
android:layout_gravity="bottom"
android:layout_margin="16dp">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/menu_main"/>
</android.support.v7.widget.CardView>
</FrameLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/lorem"
android:icon="#drawable/ic_archive"
android:title="Lorem"/>
<item
android:id="#+id/ipsum"
android:icon="#drawable/ic_archive"
android:title="Ipsum"/>
<item
android:id="#+id/dolor"
android:icon="#drawable/ic_archive"
android:title="Dolor"/>
</menu>
You can replace icon from menu with your own png Icons heaving text. And will leave title remain empty. Its tested Technique!
Completely new user of Android Studio is here, and I'm trying to make a movie review application as a school project.
So the problem here is that there will be several icons on my homepage's navigation bar, but the first icon for some reason is always blue and larger than the other icons, and I have no idea how to fix that, as you can see in the picture. Picture
Here's the XML of my homepage.xml and the nav_items.xml
HOMEPAGE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".Homepage">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="68dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:menu="#menu/nav_items"></android.support.design.widget.BottomNavigationView>
</RelativeLayout>
Nav_items.XML
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:icon="#drawable/ic_input_black_24dp"
android:title="#string/nav_list" />
<item
android:icon="#drawable/outline_home_black_24"
android:title="#string/nav_home" />
</menu>
If it is blue by default then it means it is selected.
I want to disable the line divider in my navigation menu. I tried a code out, but it doesnt worked. I hope someone can help me :)
That is the code that I tried:
<item name="android:listDivider">#android:color/transparent</item>
Ok you have to add the Style :
<item name="android:listDivider">#android:color/transparent</item>
but you have to define it as background in your divider view :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
</FrameLayout>