I m just trying to use parchment library to add an horizontal listView but it doesn't work for me.
I followed all the instructions to add parchment as an Android library in Eclipse and it's ok for this step. The problem is that when i'm trying to add my horizontal listView in xml file Eclipse shows the error : " Error: String types not allowed (at 'orientation' with value 'horizontal ')"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="#ff5a5bff"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List App"
android:textColor="#fff"
android:textSize="25sp"
android:gravity="center_vertical"
android:layout_centerInParent="true"/>
</RelativeLayout>
<mobi.parchment.widget.adapterview.listview.ListView
xmlns:parchment="http://schemas.android.com/apk/res/res-auto"
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="200dp"
android:clipToPadding="true"
android:drawSelectorOnTop="false"
parchment:orientation="horizontal"
parchment:snapPosition="start"/>
</LinearLayout>
Can you please help
Thank's a lot
Add the following to your root tag,
xmlns:parchment="http://schemas.android.com/apk/res-auto
Also your LinearLayout.TextView 60 dp centered(vertical text)may be simplified
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:parchment="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="List App"
android:background="#ff5a5bff"
android:textColor="#fff"
android:textSize="25sp"
android:gravity="center_vertical" />
in documentation xmlns is:
xmlns:parchment="http://schemas.android.com/apk/res/<YOUR PACKAGE NAME>"
and in your code is a:
xmlns:parchment="http://schemas.android.com/apk/res/res-auto"
Please check this
Related
I am new to android and I have created a simple block of code which has a scrollView and an image. I want this scrollview to scroll smoothly. What do I have to do for that ? I have gone through many materials over internet, but all of those use hard terminologies which I'm not able to understand. Can someone please help me ? Thanks.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/top_string"
android:textColor="#android:color/white"
android:textSize="16dp"
android:textScaleX="1.5"
/>
<ImageView
android:id="#+id/img"
android:layout_width="300dp"
android:layout_height="150dp"
android:src="#drawable/dg_truck_main"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_blue_light"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="#id/text_view"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/top_string2"
android:textColor="#android:color/white"
android:textSize="16dp"
android:textScaleX="1.5"
android:layout_marginTop="50dp"
android:layout_below="#id/img"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You have added ScrollView inside RelativeLayout, what I suggest is that you should place RelativeLayout inside ScrollView tag. Please go through below code,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/top_string"
android:textColor="#android:color/white"
android:textSize="16dp"
android:textScaleX="1.5"
/>
<ImageView
android:id="#+id/img"
android:layout_width="300dp"
android:layout_height="150dp"
android:src="#drawable/dg_truck_main"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_blue_light"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="#id/text_view"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/top_string2"
android:textColor="#android:color/white"
android:textSize="16dp"
android:textScaleX="1.5"
android:layout_marginTop="50dp"
android:layout_below="#id/img"
/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Okay I got my answer. Since I was new to android, I thought that "smooth scroll" is something else and we have to integrate it into our project. But a scrollView already gives smooth scrolling and so we do not need to write any extra code for that.
//to make the scrollview faster
//add the below line in xml
android:fillViewport="true"
//also add the following line to your java class
// to make the scroll view faster
scrollView.fullScroll(View.FOCUS_DOWN);
scrollView.setSmoothScrollingEnabled(true);
I had a hard time resolving this issue. Finally found a solution very simple and very smooth outcome. In your recycler view set nested scrolling to false.
Two ways to achieve it.
Through xml file -
android:nestedScrollingEnabled="false"
Through java code -
recyclerView.isNestedScrollingEnabled = false
I know there are a hundred questions here just like mine, but none of them seem to suit my specific problem, so I am asking a new question. Just in case this is a repeat, I'm sorry.
So, I am building an app, and the layout is causing me a few problems.
This is my XML code : (it's not yet complete)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/toosl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:xmlns="http://schemas.android.com/apk/res/android" >
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
The error that I'm getting is in the first line of the code
where it says "error: no resource identifier found for attribute 'xmlns' in package 'android'
I've gone over and over the code, I've tried to refresh/rebuild the project, I tried deleting that particular line, etc.. and nothing seems to solve it.
So, if anyone has some ideas?
Thanks!
Remove
android:xmlns="http://schemas.android.com/apk/res/android"
from your layout,i.e. use your layout as
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/toosl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
Replace it with this
<LinearLayout 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:layout_gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
I found my mistake, it's in the last attribute of my first LinearLayout tag.
I should not have included that line at the bottom.
I removed that line and now its working.
Thank you!
if none of the above worked make sure you add this:
compile 'com.android.support:percent:23.1.1'
to your build.gradle
I have an application called "Yamba". The only layout XML file it has is:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/titleStatus"
android:textSize="30sp" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top|center_horizontal"
android:hint="#string/hintText" />
<TextView
android:id="#+id/textCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:text="000" />
<Button
android:id="#+id/buttonId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buttonUpdate"
android:textSize="20sp" />
</LinearLayout>
The application shows everything well.
The only change I made is changing the order of (EditText id/editText") with (TextView id/textCounter) so that it becomes:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/titleStatus"
android:textSize="30sp" />
<TextView
android:id="#+id/textCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:text="000" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top|center_horizontal"
android:hint="#string/hintText" />
<Button
android:id="#+id/buttonId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buttonUpdate"
android:textSize="20sp" />
</LinearLayout>
After this change the emulator shows me: Unfortunately, Yamba has stopped" OK.
When I restore it back to its previous order, everything works well. why?
When you change the order of Views in the XML layout, their numerical IDs are changed (they are assigned from top to bottom), then when you refer to the previous ID in your code for example in findViewById() you'll get the wrong one and an ClassCastException (I guess because you didn't include the logcat).
Cleaning before building will solve the problem.
When in doubt with things that don't make sense. Project Clean/Exit eclipse and reopen.
I've encounter strange things like this before and that's ultimately what solved it.
I am trying to get the following look (screenshot from my iOS app) on the Android version of my app.
I have defined my layout file as follows in Android:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/postTextTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/shareLILayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:gravity="top|left|start"
android:inputType="textMultiLine" >
<requestFocus />
</EditText>
<LinearLayout
android:id="#+id/shareLILayout"
android:layout_alignParentBottom="true"
android:background="#999999"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:contentDescription="#string/li_btn_desc"
android:id="#+id/postToLIButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:background="#android:color/transparent"
android:src="#drawable/linkedin_switch_off" />
<TextView
android:id="#+id/postToLITextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/share_on_linkedin"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
If I swap my ImageButton and TextView above, my app just crashed with a RuntimeException! Also I am not able to center the text so that its aligned to the center of the button. What am I doing wrong?
Simply swap the ImageButton and TextView order. Your runtime error is either unrelated or is caused by the need to clean your project before you need to redeploy it (sometimes resource IDs get funky). Also use android:gravity="center_vertical" for you TextView to center it properly
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ViewFlipper
android:id="#+id/vf1"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/a1"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/left1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/left64"/>
<Button
android:id="#+id/left2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/left128"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radio12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="set0"
android:text="Select"/>
<RadioButton
android:id="#+id/radio11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="set0"
android:text="Select" />
</RadioGroup>
</RelativeLayout>
.
.
N more relative layouts like this then
</ViewFlipper>
</RelativeLayout>
when N<=3 it works fine, BUT when N>3 java.lang.stackoverflow error come directly while parsing the xml file while switching to graphical layout. I am building it on API 17. I've read in many blogs that this error occurs because of very deep hierarchy of layouts, but I don't think my hierarchy is too deep. Is it? Also is there any way to increase stack size in android? Pls provide me its solution if any1 finds it out