I am using sliding panel layout and in that i have ONE floating buttons.Now when i Click on the button the view Slides first and then i have to click again on button to perform action.
I want to perform action on only single click without the sliding movement of parent view.
Look at these images
Look at 1 images
look at this
Here is my
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="#+id/Sliding"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:id="#+id/leftSide"
android:background="#ef3"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contact"
android:background="#drawable/bg_key"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:id="#+id/rightSide"
android:layout_marginLeft="170dp"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:focusable="false"
app:srcCompat="#drawable/ic_menu_camera"
android:id="#+id/call"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/message" />
</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>
here is my java code
SlidingPaneLayout sp;
#Override
protected void onCreate(Bundle savedInstanceState)
{
context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
call = (FloatingActionButton) findViewById(R.id.call);
sp = (SlidingPaneLayout) findViewById(R.id.Sliding);
assert sp != null;
sp.setPanelSlideListener(this);
sp.setSliderFadeColor(Color.TRANSPARENT);
sp.openPane();
mList = new ArrayList<Contacts>();
call.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Log.e("CALL","CALL");
try
{
if(number.isEmpty())
{
Toast.makeText(context,"Please select contact first",Toast.LENGTH_SHORT).show();
}
else
{
calling();
number=null;
}
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(context,"This is not the valid contact",Toast.LENGTH_SHORT).show();
}
}
});
}
Use this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.SlidingPaneLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="#+id/Sliding"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:id="#+id/leftSide"
android:background="#ef3"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contact"
android:background="#drawable/bg_key"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:id="#+id/rightSide"
android:layout_marginLeft="170dp"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:focusable="false"
app:srcCompat="#drawable/ic_menu_camera"
android:id="#+id/call"
android:layout_alignParentTop="true" />
</RelativeLayout>
</RelativeLayout>
Related
There are a few buttons in my activity which do not get clicked on the first attempt but they get clicked from the second time onwards. It seems that the button gets focus on the first click and gets actually pressed from the second time onwards. What can be the reason that these buttons do not get clicked the first time?
I have noticed that this behaviour is only shown by buttons that are at the very bottom of my activity.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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.me.proj.view.activities.MallActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
app:title=" "
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager_mall_showcase_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include layout="#layout/info_card" />
<include layout="#layout/photo_card" />
<include layout="#layout/address_card" />
<include layout="#layout/opening_hours_card" />
<include layout="#layout/review_card" /> <!-- Button in this file has the problem-->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
review_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="0.5dp"
card_view:cardMaxElevation="1dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_marginTop="7dp"
android:background="#color/colorWhite"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite">
<TextView
android:id="#+id/txt_rating"
android:background="#drawable/blue_button_background"
android:text="3.8"
android:textColor="#color/colorWhite"
android:layout_marginTop="10dp"
android:textSize="24sp"
android:gravity="center"
android:layout_marginStart="10dp"
android:layout_width="60dp"
android:layout_height="40dp" />
<TextView
android:id="#+id/txt_reviews_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:layout_toEndOf="#+id/txt_rating"
android:layout_marginStart="20dp"
android:textStyle="bold"
android:paddingTop="1dp"
android:layout_alignTop="#+id/txt_rating"
android:text="Based on 98 reviews"/>
<TextView
android:id="#+id/txt_read_all_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read All Reviews"
android:layout_alignStart="#id/txt_reviews_title"
android:layout_toEndOf="#id/txt_rating"
android:layout_alignBottom="#id/txt_rating"
android:gravity="bottom"
android:paddingBottom="1dp"
android:textColor="#color/red"
android:layout_below="#id/txt_reviews_title"/>
<View
android:id="#+id/view_dummy1"
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:layout_below="#id/txt_read_all_reviews"
android:layout_marginTop="10dp"
android:background="#color/divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="16dp"
android:layout_below="#+id/view_dummy1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/txt_how_did_your_visit_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How did your visit go?"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#color/primary_text" />
<TextView
android:id="#+id/txt_tell_everyone_about_it"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tell everyone about it!"
android:layout_marginTop="5dp"
android:textColor="#color/secondary_text"
android:textSize="12sp"
/>
</LinearLayout>
<!--This got some problem-->
<Button
android:id="#+id/btn_add_review"
android:layout_width="0dp"
android:layout_height="40dp"
android:text="Add Your Review"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:background="#drawable/blue_button_background"
android:layout_weight="0.5"/>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_add_review).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "clicked", Toast.LENGTH_SHORT).show();
}
});
}
Code in my MainActivity.class:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view = findViewById(R.id.sub_layout);
Button button = (Button) view.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Do your stuff
Toast.makeText(MainActivity.this, "hi", Toast.LENGTH_SHORT).show();
}
});
}
}
Code in my activity_main.xml
<?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="eflair.myapplication.MainActivity">
<include
android:id="#+id/sub_layout"
layout="#layout/sub_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
Code in my sub_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
This issue is actually a bug in the NestedScrollView class for a while now.
I solved this issue my making some tweaks to the source code of the NestedScrollView class, as follows :-
public class NestedScrollView extends FrameLayout implements NestedScrollingParent,
NestedScrollingChild, ScrollingView {
...
#Override
public boolean onTouchEvent(MotionEvent ev) {
switch (actionMasked) {
case MotionEvent.ACTION_DOWN: {
if (getChildCount() == 0) {
return false;
}
//add this condition
if (!inChild((int) ev.getX(), (int) ev.getY())) {
return false;
}
if ((mIsBeingDragged = !mScroller.isFinished())) {
final ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
}
...
}
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
...
switch (action & MotionEventCompat.ACTION_MASK) {
...
case MotionEvent.ACTION_DOWN: {
...
// replace this line:
// mIsBeingDragged = !mScroller.isFinished();
mIsBeingDragged = false;
...
}
}
}
}
After doing this it should work fine.
I have one relativeLayout and three view's inside RelativeLayout. There views are place on each other.
<RelativeLayout
android:id="#+id/includelayoutgroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparentColorView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<include
layout="#layout/transfer_keyboard_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/finalRequestView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<include
layout="#layout/fragment_transfer_new_version_container_child"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
Is it a possible to reverse position my view's? I mean,in my code last Layout is finalRequestView and in button click i would to my last view in first position,and other view's place on my view,
How i can solve this problem?
I try to reverse layout by following demo & it works as you want, please take a look
ReverseLayout.java
public class ReverseLayout extends AppCompatActivity {
LinearLayout llRoot;
Button btReverseLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reverse_layout);
llRoot = (LinearLayout) findViewById(R.id.llRoot);
btReverseLayout = (Button) findViewById(R.id.btReverseLayout);
btReverseLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<View> alViews = new ArrayList<View>();
for (int i = llRoot.getChildCount() - 1; i >= 0; i--) {
View view = llRoot.getChildAt(i);
llRoot.removeViewAt(i);
alViews.add(view);
}
for (int j = 0; j < alViews.size(); j++) {
llRoot.addView(alViews.get(j));
}
}
});
}
}
reverse_layout.xml layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tosc185.testproject.Activity6">
<LinearLayout
android:id="#+id/llRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btReverseLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Reverse Layout" />
</RelativeLayout>
I am trying to implement a panel in a fragment that can expand on button click from the right side of the screen. I can't use the navigation drawer, because I already have navigation drawers from both left and right sides.
The idea is to achieve something like that:
I was almost able to do it with the SlidingDrawer widget (it's deprecated..), the only problem is that I don't know how to make the LinearLayout to appear in the middle and then to shift when the button to expand the SlidingDrawer is clicked.
I have the following code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button handle = (Button) findViewById(R.id.handle);
SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
}
});
}
}
And the XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.test.slidingdrawertest.slidingdrawertest.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="200dp"
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_gravity="end"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal">
<Button
android:id="#+id/handle"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expand" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</RelativeLayout>
You can edit your XML like this
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:padding="10dp"
tools:context="com.test.slidingdrawertest.slidingdrawertest.MainActivity">
<LinearLayout
android:id="#+id/left" // this is your linear layout
android:layout_width="match_parent" // that you want to shift left
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/right" // apply this property due to
android:layout_alignParentLeft="true" //which if the width of sliding menu
android:gravity="center" //increase it will automatically compressed
android:background="#aa00aa"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:background="#0000aa"
android:layout_height="match_parent">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="200dp" // you can check by increasing or decreasing the with of this slidingdrawer
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_gravity="end"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal">
<Button
android:id="#+id/handle"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expand" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TEST" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</RelativeLayout>
apart from this if set any layout to the right of your linear layout which is initially GONE and as you click on the button its visibility changed to INVISIBLE/VISIBLE so it will shift the linear layout to left. Hope that helps!
If you want a little exemple here is my solution: (I don't know if Avani Nagar's solution works or not):
TextView res;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView img = (TextView)findViewById(R.id.second);
res = (TextView)findViewById(R.id.first);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
img.setX(img.getX() - 5);
changew(img.getX());
}
});
}
private void changew(float w){
res.getLayoutParams().width = (int)(res.getX() +w);
res.requestLayout();
res.invalidate();
}
The 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"
android:background="#android:color/black">
<TextView
android:layout_toRightOf="#+id/first"
android:text="bonjourrrrrr"
android:id="#+id/second"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="#android:color/holo_red_dark" />
<TextView
android:text="salutttttttt"
android:id="#id/first"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="#android:color/holo_green_light" />
</RelativeLayout>
I managed to do it, it actually wasn't so difficult, but it's a little tricky. Here is the solution:
The xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:id="#+id/topLayout"
tools:context="com.test.slidingdrawertest.slidingdrawertest.MainActivity">
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST" />
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:layout_width="200dp"
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_gravity="end"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal">
<Button
android:id="#+id/handle"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expand" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEST TESTT" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
</RelativeLayout>
The code in MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button handle = (Button) findViewById(R.id.handle);
SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);
final View k = findViewById(R.id.mainLayout);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
k.setLayoutParams(params);
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
k.setLayoutParams(params);
}
});
}
}
And the explanation: I had to give main main layout an id (in XML) and then find it in the code behind, then I had to apply new parameters to it when the drawer opens or closes. Basically, we need to find the parent layout and set the parameters to it.
Now the LinearLayout is able to shift it's position on drawer open, and it goes back to it's original position on drawer close. Next step is to make this process with an animation, so it's smooth and doesn't just jump back and forth to the new positions.
i want to implement Globe-Weis File Folder like picture below which by clicking on green button it scrolling smoothly up and by clicking on the green button again ,the folder page scrolling down smoothly.
what i try so far was putting three scrollView in a frameLayout , and to open and close it
if (!underIsOpen) {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_botton).getTop())
.setDuration(1000).start();
underIsOpen = true;
} else {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_s_part).getTop())
.setDuration(1000).start();
underIsOpen = false;
}
but it just work on the scrollView which is on top
my code is:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test3);
ll_under_s_part = (LinearLayout) findViewById(R.id.ll_under_s_part);
sv_Under = (ScrollView) findViewById(R.id.scrollView1);
sv_Mid = (ScrollView) findViewById(R.id.scrollView2);
sv_Top = (ScrollView) findViewById(R.id.scrollView3);
}
public void onClick_under_left(View v) {
Toast.makeText(getApplicationContext(), "under layout",
Toast.LENGTH_SHORT).show();
if (!underIsOpen) {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_botton).getTop())
.setDuration(1000).start();
underIsOpen = true;
} else {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_s_part).getTop())
.setDuration(1000).start();
underIsOpen = false;
}
}
public void onClick_mid_left(View v) {
Toast.makeText(getApplicationContext(), "mid layout",
Toast.LENGTH_SHORT).show();
}
public void onClick_top_left(View v) {
Toast.makeText(getApplicationContext(), "top layout",
Toast.LENGTH_SHORT).show();
if (!topIsOpen) {
ObjectAnimator
.ofInt(sv_Top, "scrollY",
findViewById(R.id.ll_top_botton).getTop())
.setDuration(1000).start();
topIsOpen = true;
} else {
ObjectAnimator
.ofInt(sv_Top, "scrollY",
findViewById(R.id.ll_top_s_part).getTop())
.setDuration(1000).start();
topIsOpen = false;
}
}
xml:
<?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="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_under_s_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#ccff00"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/ll_under_botton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#519B57"
android:onClick="onClick_under_left"
android:orientation="vertical"
android:text="B T N" />
<LinearLayout
android:id="#+id/ll_under_p_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#edf5ee"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_under_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_under_2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1000dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_mid_s_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#00000000"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_mid_3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/ll_mid_botton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#088da5"
android:onClick="onClick_mid_left"
android:orientation="vertical"
android:text="B T N" />
<LinearLayout
android:id="#+id/ll_mid_p_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#e6f3f6"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_mid_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_top_s_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#00000000"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_top_3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_top_2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/ll_top_botton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#D11141"
android:onClick="onClick_top_left"
android:orientation="vertical"
android:text="B T N" />
<LinearLayout
android:id="#+id/ll_top_p_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#fae7ec"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
the second way i tried was using animation but no success to result i am looking for :
public void SlideUP(View view, Context context) {
view.startAnimation(AnimationUtils.loadAnimation(context,
R.anim.slid_up));
}
public void SlideDown(View view, Context context) {
view.startAnimation(AnimationUtils.loadAnimation(context,
R.anim.slid_down));
}
any other way that i can implement this?
I don't think adding so may layout on a single screen with scrollbars is a good idea, you can apply simple frame layouts and list them accordingly and when clicking on any of the desired folder icons just animate it towards top, and it will also show the content of the folder.
https://github.com/kikoso/Swipeable-Cards
you could customize this library to do that, I have done a similar kind of app and applied the same library with my custom changes.
With the layout below the buttons are being shown on top of the page. How can I make them appear below, after the container, down on the page?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/Main"
android:onClick="ClickHomePage"
android:text= "#string/Home"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/map"
android:onClick="ClickClients"
android:text= "#string/Clients"
>
</Button>
</LinearLayout>
</LinearLayout>
The MainActivity looks as follows and the HomePage.xml is also below
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GetButtonClicked(5);
setContentView(R.layout.activity_main);
}
public void GetButtonClicked(int position)
{
// update the main content by replacing fragments
Fragment fragment = null;
switch (position){
case 0:
fragment= new FirstPageFragment();
break;
default:
fragment = new FirstPageFragment();
break;
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
public void ClickHomePage(View view){
GetButtonClicked(0);
}
public void ClickClients(View view){
GetButtonClicked();
}
}
<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.test.FirstPageFragment" android:background="#drawable/theme">
</FrameLayout>
This is the FirstPage
public class FirstPageFragment extends Fragment {
public FirstPageFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first_page, container, false);
}
}
Use ralative layout insted of linear.
Make a different layout for bottom buttons, and then at the last of your container layout use this:
<include android:id="#+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="#layout/bottom_buttons"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickHomePage"
android:text="#string/Home" />
<Button
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickClients"
android:text="#string/Clients" >
</Button>
</LinearLayout>
Try this
Use RelativeLayout with android:layout_alignParentBottom="true" step by step guide is available here.
Your skeleton for layout should look like this
<RelativeLayout
<LinearLayout android:layout_alignParentBottom="true">
<Button
<Button
</LinearLayout>
</RelativeLayout>
Final Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickHomePage"
android:text="Home" />
<Button
android:layout_marginLeft="30dp"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickClients"
android:text="Clients" >
</Button>
</LinearLayout>
The issue was that I did not include the container in another layout...
<RelativeLayout 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.test.MainPageActivityActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="#+id/container">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentTop="#+id/container">
and insert buttons layout here....
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/Main"
android:onClick="ClickHomePage"
android:text= "#string/Home"
/>