I set ViewPager's height wrap_content but it doesn't work. I tried answers in other similar questions but they didn't solve my problem. my activity_main code is this:
<?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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C49A1544"
tools:context=".MainActivity">
<include layout="#layout/toolbar"
android:id="#+id/main_toolbar"/>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewpager"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/standard_margin_x2"
android:layout_below="#id/main_toolbar"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
and I have 3 fragment layouts. really sorry for my low English, I am a beginner in Android app development please help me.
I found a solution myself. If we use UltraViewPager library instead of the default, the problem will be solved, but this library has bugs. Anyway, thank you for trying to help me with your comments.
Related
I added a new android wear module based on this Google doc
but I am getting the error described in the title. Here is my layout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout 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/dark_grey"
android:padding="#dimen/box_inset_layout_padding"
tools:context=".MainWearActivity"
tools:deviceIds="wear">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/inner_frame_layout_padding"
app:boxedEdges="all"> <---this is the offending line
<android.support.v7.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</FrameLayout>
</android.support.wear.widget.BoxInsetLayout>
Anyone know what's going on? I appreciate explanation as to why I am getting this error.
UPDATE: I removed the redundant android prefix. Android studio requires me to change the app prefix to change to android but even after doing so the error remains. Is it safe time to assume it is a bug?
Based on what Mike M suggested, I right clicked on the error and I selected suppress in Android studio. My Framelayout now looks like this. I do not however currently know what caused the warning.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/inner_frame_layout_padding"
app:boxedEdges="all"
tools:ignore="MissingPrefix">
This seems to work for now.
Hello evreyone,
I get this error from my Layout XML: Multiple root error. So I tried a lot to fix it yet could not find any solution, please help me about it:
this is my code from file layout xml:
thanks a lot :)
You can have only one element in your XML that doesn't have a parent. By sparse information you gave us, you have at least two root elements: <RelativeLayout> and <android.support.v4.widget.DrawerLayout >.
To fix this error you just need to move </RelativeLayout> (closing tag) after DrawerLayout, that is to the end of the document. Or, probably better, move <android.support.v4.widget.DrawerLayout > to the beginning, enclosing other layouts.
However even if you do fix error you're getting this is not good implementation. You should read more about DrawerLayout.
you are getting Multiple root error in Layout because of
in Android every xml file there must be only one root layout
so try to add single parent to your layout
sample code
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- add here your other controlls or layouts-->
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_home_class"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view_home"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_home_class"
app:itemBackground="#android:color/transparent"
app:itemIconTint="#color/drawer_item"
app:itemTextColor="#color/drawer_item"
app:menu="#menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Can any one please tell me, how to disable segmentedcontrol in android.
I have been using Foursquared library.
The link for library is given below.
You can do one thing for that.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SegmentedButton
android:id="#+id/login_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
/>
<Layout
android:id="#+id/transperent_fragment"
android:name="com.test.transperentFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/body_texture"
android:alpha="0.2"
android:clickable="true"/>
</RelativeLayout>
Hope this helps you..:)
I am trying to build up android app layout and my problem is that one element has some weird padding/margin and I can't find where it's been given. I triple checked my code and I'm sure that elements in my XML layout have no specific margins or padding (images attached). Is there any way to figure out what is going on? I have turned on show element borders on my device and it wasn't very helpful. I'm a beginner in the Android world and I wonder is there any specific tool to help in this kind of situation? I would be grateful for any kind of advice. Thanks!
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/monthPageTitlePageIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:clipToPadding="false"
app:backgroundTintMode="multiply"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/white" />
<android.support.v4.view.ViewPager
android:id="#+id/historyViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AAAAAA" />
</LinearLayout>
The red line below shows the unwanted space:
The following shows the borders:
Here is my layout xml.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/garae_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:fillViewport="true"
android:focusableInTouchMode="false" >
<RelativeLayout>
...
<com.handmark.pulltorefresh.library.PullToRefreshScrollView>
<LinearLayout/>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</RelativeLayout>
</ScrollView>
I already tried the solution in this link:
ScrollView Inside ScrollView
However, it didn't work. How can do use child PullToRefreshScrollView??
Please help me.
If I understand your question, you want to implement a Pull to refresh in your Scrollview. Instead, to use the library you are using, I would suggest you to implement a SwipeRefreshLayout
https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
It is a layout that implements a pull-to-refresh like in the application of Google+ or Gmail.
Here's an example implementing SwipeRefreshLayout in your xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/garae_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
NOTE
It is highly not recommended to put a Scrollview/Listview inside a Scrollview/Listview. The first reason is about the performance and Romain Guy explains that in one video https://www.youtube.com/watch?v=wDBM6wVEO70