AndroidStudio: How to move a button in a fragment - java

How can i move in Android Studio elements like buttons or textViews within a fragment? In an Activity i can take the button with drag&drop, but this seems not to work within fragments.
So now my button is in the left corner, but i wish to place them in the middle.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.fragmenttest.BlankFragment">
<Button
android:id="#+id/button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>

set android:gravity="center" in your parent FrameLayout

There is no difference if you're using fragments or activities, it's all about your layout type. Try to use ConstraintLayout instead of yours or set android:gravity="center" in your FrameLayout.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Button" />
</android.support.constraint.ConstraintLayout>
Or:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="center"/>
</FrameLayout>

Related

How can I achieve overlapping card views inside Recycler view?

Basically what I need is overlap the views
View to achieve
Each cardview is an item and will be contained within a recyclerview
this is how my card view is defined
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="-11dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
>
<android.support.v7.widget.CardView...>
</ScrollView>
<ImageView
android:layout_width="70dp"
android:layout_height="40dp"
android:src="#drawable/img_food_little"
android:layout_alignParentEnd="true"
android:layout_marginEnd="40dp"
/>
</RelativeLayout>
And looks like (The blue one is the RelativeLayout):
How my item card view
Please Help
Try to replace the linear layout in the following with cardview and use the resultant layout as the layout for the recyclerview items .
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_marginTop="20dp"
android:background="#cccccc"
android:layout_height="100dp">
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:src="#mipmap/ic_launcher"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:layout_height="wrap_content" />
</FrameLayout>
Hope this helps.

How to Control Visibility of items in a Linear Layout in my App?

I have a Vertical linear layout with 2 item. One is a is a customview which is extended from a framelayout and the 2nd one is a textview with a drawable as background. The visibility have to be controlled dynamically from gone to visible.
The issue is that when i change the visibility of the item from gone to visible the order is not coming as i intended. The the second item is below the customview. I want it to come as the 2nd item, below the customview
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:textureview="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="#+id/comment_holder"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.custom_views.CircularFrameLayout
android:id="#+id/comment_holder_circular_layout"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/user_avatar"
android:visibility="gone"
android:layout_gravity="center_horizontal"
android:layout_width="#dimen/comment_avatar_width"
android:layout_height="#dimen/comment_avatar_width" />
<com.custom_views.PlaybackTextureView
android:visibility="gone"
android:id="#+id/playback_texture_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
textureview:isAuthorMode="true"/>
</com.custom_views.CircularFrameLayout>
<LinearLayout
android:visibility="gone"
android:id="#+id/c_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="16dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:background="#drawable/chat_bubble_top_arrow_orange"
android:orientation="vertical">
<TextView
android:id="#+id/video_comment_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#color/black_50"
android:fontFamily="sans-serif" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
NOTE: I tried adding weight to the custom layout as 1. But it still didnt help.

Scrolling of multiple recycler view in an activity. (how to make it smooth)

I have 2 recyclerviews in my activity 1st one is horizontally scrollable and the 2nd one is vertically scrollable. (XML code given below)
But the scrolling is not smooth.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:clickable="true"
>
<ProgressBar
android:id="#+id/progressBarCircularIndetermininatesearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#f44336"
android:layout_centerInParent="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/progressbacklin"
android:scrollbars="none"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/videolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentTop="true"
android:scrollbars="none"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_below="#+id/videolist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:scrollbars="none"
/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/progressbacklin"
android:layout_above="#+id/adViewsearch"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginBottom="90dp"
android:layout_marginTop="5dp"
android:background="#drawable/white"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
>
<ProgressBar
android:id="#+id/progressBarCircularIndetermininate"
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminateTintMode="src_atop"
android:indeterminateTint="#f44336"
android:layout_centerInParent="true"/>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adViewsearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id" />
</RelativeLayout>
i use
setNestedScrollingEnabled(false);
for both recycler view.
Any ideas to implement this with a smooth scrolling?
Change ScrollView to NestedScrollView.
In order this to work, you need to have RecyclerView with height wrap_content inside NestedScrollView and you need to set recyclerView.setNestedScrollingEnabled(false) from code.
How i solved this problem is by using a single Recycler view instead of two and setting up the other (1st recycler view in question) recycler view as first item of it.
Now it works perfect and scrolling smoothly.

Android: Swipe to refresh gets stuck on a recycler view with view pager

Here is my XML code
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/flipper">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/headerLayout"
android:background="#color/background_color"
android:visibility="visible">
<android.support.v7.widget.RecyclerView
android:id="#+id/list_appointment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="#+id/emptyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone">
<ImageView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_event_note"
android:textAppearance="?android:textAppearanceMedium" />
</RelativeLayout>
</FrameLayout>
The RecyclerViews adapter supports two types of views one is CardView and another is ViewPager.
When I swipe to refresh, the circular refresh icon freezes on top of the ViewPager.onrefresh method is called after I tap the refresh icon again.Is there any fix to this issue?

Android add image on top of another imageView as image below in Layout XML

How to create a android Layout where you add a smaller imageView on Top of another Image View. but only half way as the image below.
Thank.
this is the sample I try but it does not work:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageCover"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/big_cover_img" />
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBottom="#+id/imageCover"
android:layout_centerHorizontal="true"
android:src="#drawable/profile_pic" />
<!-- android:layout_alignBottom="#+id/imageCover" -->
</RelativeLayout>
Use FrameLayout as parent and LinearLayout as child with weight property :
<FrameLayout 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="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:id="#+id/imageCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/big_cover_img" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="#drawable/ic_launcher" />
</FrameLayout>
Set the second view to be below the first then set top margin of the bottom view to -50 dp or whatever value you want it to overlap

Categories

Resources