Troubles with AndroidSlidingUpPanel with Eclipse - Error Inflating class - java

I'm trying to use the AndroidSlidingUpPanel library (in Eclipse) and I have this error:
04-19 20:09:48.413: E/AndroidRuntime(13760): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mendozatourapp/com.mendozatourapp.activitys.MapsActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.sothree.slidinguppanel.library.SlidingUpPanelLayout
This is my layout:
<?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=".DemoActivity" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/lib/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp"
sothree:paralaxOffset="100dp"
sothree:dragView="#+id/name">
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</RelativeLayout>
I downloaded the entire project and imported "main" as library. Then I add this library to my project's java build path. I have the feeling that is a java build path problem. Any idea?
Thank you so much for reading me and take your time to do it.

I just got it working in Eclipse.
The important part is to get your library project created correctly and then link it up to your main project.
For the library project, I created a project.properties file, and also added the jar files for the RecyclerView library, the support v4 library, and nineoldandroids.
I also created a .classpath file in order to make it automatically put the java folder in the build path.
I uploaded the library project that I got working to github: https://github.com/dmnugent80/SlidingUpPanel-for-Eclipse/tree/master
Then, import the library project into your workspace:
Set it up as a dependency of the main project:
So, you end up with something like this:
Then, using this test xml (your xml threw an error about needing a minimum of two children):
<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoDragView="#+id/dragView"
sothree:umanoOverlay="true"
sothree:umanoScrollableView="#+id/list">
<!-- MAIN CONTENT -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="Main Content"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="true"
android:textSize="16sp" />
</FrameLayout>
<!-- SLIDING LAYOUT -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="#+id/dragView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="14sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>
<Button
android:id="#+id/follow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="14sp"
android:gravity="center_vertical|right"
android:paddingRight="10dp"
android:paddingLeft="10dp"/>
</LinearLayout>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
It works!

Related

android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class android.support.v7.widget.Toolbar

<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="#drawable/background"
android:layoutDirection="ltr"
android:paddingBottom="25sp"
android:paddingLeft="5sp"
android:paddingRight="5sp"
android:paddingTop="25sp"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="25dp"
android:src="#drawable/mainlogo"
android:id="#+id/ClickHereToEnter"
android:layout_marginBottom="25dp"
android:gravity="center">
</ImageView>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/lunch"
android:layout_marginBottom="15dp"
android:textColor="#90A4AE"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>
This error appears to me and I don't know why?? and can't solve it any help, please?
when run application this error appear to me and detected error in java page in line 17
(setContentView(R.layout.activity_main))!!! so can anyone help me?
you have to add to your XML file , I hope it will help you .
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:titleTextColor="#android:color/black" />
I reckon you may be using Toolbar of support library and having dependencies of androidx.Check your dependency in build.gradle whether it is androidX or support library and accordingly use that Toolbar in your xml layout file.

Same Java file for two layouts (XML)

I have 2 layouts for my application
but I have written all my Logic in MainActivity.JAVA
I want to use MainActivity.JAVA for my other layout (XML) file also
How can I do that?
This is my MainActivity.XML (Layout File)
Now I want Blue Button on Right to resize the new layout for that
New XML (with no Java file) only Layout file
Now I want to use the same Java file (MainActivity.JAVA)
For this new layout file
You have to use a Fragment or another solution is that include layout. You said you have one common activity and in this activity you need to include two XML layout then you can set like this:-
You can use the include element to have sub-XML files:
main.xml
<LinearLayout ... >
<include layout="#layout/file1" />
<include layout="#layout/file2" />
</LinearLayout>
file1.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/toolbar_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="#+id/iv_toolbar_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:visibility="gone" />
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:ellipsize="end"
android:gravity="center_horizontal"
android:padding="10dp"
android:singleLine="true"
android:text="MyApp"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
file2.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:id="#+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#color/colorPrimaryDark"
tools:context="com.inducesmile.androidmusicplayer.SplashActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logomusic"
android:contentDescription="#string/app_name"/>
</LinearLayout>
</LinearLayout>
In your main activity layout, you could use a FrameLayout, which you can then add a fragment to. Then in the Java file, you can use getSupportFragmentManager().beginTransaction().replace() method to inflate the layout XMLs as and when you like.
If you have two XML files, you can merge both of them by including one into another.
For example: if you have two files named a.xml and b.xml, then you can include the b.xml in a.xml using include tag like
<include layout="#layout/b.xml" />
Then call setContentView (R.layout.a) in your MainActivity.java
Or, you can make use of Fragments.

Android Studio include tag - invalid layout reference

I want to include one layout file in another. I made a layout view_camera_and_title.xml. I can render it in design window in Android Studio, everything works correctly.
But when I'm trying to include it in another layout file (it's named fragment_note.xml) and run application I'm getting a InflateException with the following error: android.view.InflateException: You must specifiy a valid layout reference. The layout ID #layout/view_camera_and_title is not valid.
I saw all topics on stackoverflow with the same error but nothing works for me. I tried to clean project, to restart Android Studio. All my layout files and id_values have no uppercase symbols. No result.
My include tag is without android prefix:
<include layout="#layout/my_layout"/>
These are my layout files:
view_camera_and_title.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="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="4dp">
<ImageView
android:id="#+id/note_photo"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerInside"
android:background="#android:color/darker_gray"
android:cropToPadding="true"/>
<ImageButton
android:id="#+id/note_camera"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_menu_camera"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/note_title_label"
style="?android:listSeparatorTextViewStyle"/>
<EditText
android:id="#+id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:hint="#string/note_title_hint"/>
</LinearLayout>
</LinearLayout>
fragment_note.xml
<?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">
<include layout="=#layout/view_camera_and_title"/>
<Button
android:id="#+id/note_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"/>
<Button
android:id="#+id/note_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"/>
<CheckBox
android:id="#+id/note_solved"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="#string/note_solved_label"/>
<Button
android:id="#+id/note_partner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="#string/note_partner_text"/>
<Button
android:id="#+id/note_partner_call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="#string/note_no_partner_call_text"/>
<Button
android:id="#+id/note_sharing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="#string/note_sharing_text"/>
</LinearLayout>
Does anybody know solution for this problem?
Thank you.
You have <include layout="=#layout/view_camera_and_title"/>. I think it should be <include layout="#layout/view_camera_and_title"/>, '=' is unnecessary.
You have a stray '=' character in:
<include layout="=#layout/view_camera_and_title"/>

Changing xml or layout during runtime

on my Android project I need to change the color of a xml property: app:footerColor="#1573D6" dynamically during runtime. How can I achieve this?
I could change the layout too during the running of the App, but I looked for how to do it and couldn't find anything.
Some help would be great. Thank you very much.
Here's my xml:
<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="fill_parent"
android:layout_height="fill_parent" >
<com.viewpagerindicator.TitlePageIndicator
android:id="#+id/tabloid"
android:padding="10dip"
android:layout_height="40dp"
android:layout_width="fill_parent"
android:background="#000000"
android:textColor="#1573D6"
app:footerColor="#1573D6"
app:footerLineHeight="2dp"
app:footerIndicatorStyle="none"
app:selectedColor="#FFFFFF"
app:selectedBold="true" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
you can do this in code:
TitlePageIndicator indicator =(TitlePageIndicator)findViewById(R.id.yourview)
indicator.SetFooterColor(Color.parse( #1573D6))

If I use weight layout, then my Java file cannot find the view by id

I have an XML layout using weight layout like this.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
In my Java file, I do like this, then my app crashes. If I don't use the weight layout, everything works fine.
WebView wv = (WebView) findViewById(R.id.webView1);
I think everything is fine. If you are using eclipse then Go to project -> clean and clean your project. then try to run or else restart your adb and eclipse. Then try to run.
The app works if I switch the webview and viewpage position like this:
<?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:weightSum="2"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
Try to set height for both of the controls as match_parent instead of 0dp

Categories