Hello I am starting with Android developing. I am just modifying with ECLIPSE an open source example. I have only modified strings.xml and some .png files. In the Android simulator it works perfect but when I try to generate the signed apk file I receive two errors with similar description. This is one of them (the line is marking with *):
Description #+id/about_us_desc_webview is not a sibling in the same RelativeLayout cc3x_about_us.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_background"
android:orientation="vertical" >
<include
android:id="#+id/cc3x_about_header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/cc3x_headerlayout" />
<TextView
android:id="#+id/about_us_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cc3x_about_header_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/about_title_label_top_margin"
android:text="#string/about_us_label"
android:textColor="#color/grey_text_color"
android:textSize="#dimen/extra_large_text_size"
android:textStyle="bold" />
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="#dimen/min_divider_height"
android:layout_below="#+id/about_us_textview"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:background="#drawable/about_page_divline" />
<WebView
android:id="#+id/about_us_desc_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view1"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:layout_marginTop="#dimen/min_margin_cutoff" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/about_us_desc_webview" >
<TextView
android:id="#+id/about_screen_contact_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
* android:layout_below="#+id/about_us_desc_webview"
android:layout_centerHorizontal="true"
android:text="#string/contact_label"
android:textColor="#color/grey_text_color"
android:textSize="25dip"
android:textStyle="bold" />
<View
android:id="#+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="#dimen/min_divider_height"
android:layout_below="#+id/about_screen_contact_label"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:background="#drawable/about_page_divline" />
<TextView
android:id="#+id/about_xcube_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/divider_bottom"
android:layout_margin="#dimen/max_margin_size"
android:autoLink="web"
android:text="#string/xcube_url"
android:textColor="#color/blue_text_color"
android:textColorLink="#color/blue_text_color"
android:textSize="10dip" />
<TextView
android:id="#+id/about_xcube_contact_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/divider_bottom"
android:layout_margin="#dimen/max_margin_size"
android:autoLink="email"
android:text="#string/xcube_contact_email"
android:textSize="#dimen/small_text_height" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/about_xcube_link"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/about_xcube_address"
android:textColor="#color/grey_text_color"
android:textSize="#dimen/small_text_height" />
</RelativeLayout>
</RelativeLayout>
Any help will be apreciated. Thank you very much!!
The line
android:layout_below="#+id/about_us_desc_webview"
in your TextView is redundant. Since the RelativeLayout already has that attribute, it is useless. You can just erase that line and nothing should change.
And the reason it generates error is that, you can apply features such as below, above.. etc with an element in the same layout. Here "about_us_desc_webview" is out of the RelativeLayout and you cannot position something inside a RelativeLayout with something outside a RelativeLayout.
android:layout_below
Positions the top edge of this view below the given anchor view ID .
When Arise
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:id="#+id/rl_rootHeader"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rl_Header"
android:layout_below="#+id/rl_rootHeader" // Arise ,In here RelativeLayout is Parent .
>
//
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true"
android:id="#+id/scrollRoot"
android:background="#color/colorWhite"
>
</ScrollView>
Right Way
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:id="#+id/rl_rootHeader"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rl_Header"
>
//
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true"
android:id="#+id/scrollRoot"
android:background="#color/colorWhite"
android:layout_below="#+id/rl_rootHeader" // Call Here .This section is Child
>
</ScrollView>
In my case, The problem was with Kotlin Version. I updated the the Kotlin version and the problem "is not a sibling in the same RelativeLayout" resolved
Just remove the lines which are causing error from layout
.xml file
Try refreshing the layout
Your layout will probably change. You can now reset it properly.
If you go to Properties Panel you will see layout:alignComponent has some alignment shown as "Not Found". Just clear it out. In the above example Properties window -> textview -> layout:alignComponent check all alignment values.
Related
hello i am trying to wrap a textview that has a long text. but when i test it, it just goes beyond the screen. What im trying to do is it will go to the next line if the text is long and it automatically adjust the layout. I am using this in a listview.
i am referring to this old question Android TextView Text not getting wrapped, it works on him so i tried to implement it but it wont effect on mine. thanks for answering.
here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:background="#e6e6e6"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="4dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_reviewer_name"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceLarge"
android:text="Reviewer Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="5dp"
android:id="#+id/tv_review_details"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Review"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:width="0dip"/>
</LinearLayout>
</LinearLayout>
UPDATE
here's my listview:
<ListView
android:divider="#android:color/transparent"
android:dividerHeight="2.0sp"
android:id="#+id/lv_reviews"
android:background="#f2f2f2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
You can use the inputType to auto manage a multiline text.
<TextView
android:layout_marginTop="5dp"
android:id="#+id/tv_review_details"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Review"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:width="0dip"
android:inputType="textMultiLine"
/>
if i use listView or recyclerView, i well put the layout width match parent as mentioned below:
<LinearLayout
<!--change to match_parent-->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:padding="4dip"
android:layout_weight="1">
try it once, hope this will help you.
problem solved. it turns out android studio didnt update my changes when i ran my app. i uninstalled the app and then run it again and it works perfectly.
When you are using Gravity in vertical orientation, you have to use layout_height=0dp & when you are using Gravity in Horizontal orientation then you have to use layout_width=0dp for every child of Linear Layout so that it can resize the layout by itself
<LinearLayout
android:background="#e6e6e6"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="4dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_reviewer_name"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceLarge"
android:text="Reviewer Name"
android:layout_width="wrap_content"
android:layout_height="0dp" />
<TextView
android:layout_marginTop="5dp"
android:id="#+id/tv_review_details"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Review"
android:layout_height="0dp"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>
I am creating an Android app which has a main RelativeLayout and some LinearLayout within it.
Now i have this problem. When dragging items to the editor, e.g. a LinearLayout, it doesn't fit to the full width of the screen. How can I make this possible? This is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:gravity="fill"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/itemDetailLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/itemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true" >
<TextView
android:id="#+id/itemRecentHigh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent High" />
<TextView
android:id="#+id/itemRecentLow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent Low" />
<TextView
android:id="#+id/itemAverage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Average" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/listViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/itemDetailLayout"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:gravity="fill_horizontal"
android:orientation="vertical" >
<ListView
android:id="#+id/searchListView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
</ListView>
</LinearLayout>
Added a screenshot for more info. Added blue background to have some contrast.
Replace this:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
With
android:layout_width="match_parent"
android:layout_height="wrap_content"
into your LinearLayout or Remove all the Padding from main RelativeLayout
Removing padding makes the linear layout fit the entire screen of the device
The space between the blue part and the "end of the screen". On the sides and above the part where the back button and home button are.
Remove the padding from the root RelativeLayout.
Try
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical>
// Other views within the linear layout
</LinearLayout>
I suppose you are using Eclipse. Personally, I hate the Graphical Editor of Eclipse and I usually write the XML code directly because working with the editor is a real pain
Don't use fill_parent as it is deprecated.
Instead to your RelativeLayout set
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Then, to the list view that you want to fill the rest of the screen, you can set this tags
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
By doing so, you are telling the XML that you want your ListView to do what fill_parent used to do in previous versions of Android.
Kind regards!
you should try something like the following :
<LinearLayout
android:id="#+id/itemDetailLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
...
</LinearLayout>
what i mean you should do this :
android:layout_width="fill_parent"
for every LinearLayout that you want its width to fill_parent .
FILL_PARENT means that the view wants to be as big as its parent as mentioned in the documentation .
and please give me some feedback
Hope That Helps .
I have this simple activity in my android app but I don't know how to place my button so it appears at the same position on various screen sizes.
I want the button to always be placed at the bottom of the screen. The screenshot shown is from a phone screen. When displayed on a larger screen the button is higher up.
How can I fix this?
Thanks
See this screenshot
You can use RelativeLayout with this parameter (android:layout_alignParentBottom="true")
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Click Me!"/>
</RelativeLayout>
You should use a RelativeLayout
If you have a RelativeLayout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.
If your button at the bottom doesn't show then probably the layout above it takes all the space. In this case you can put the button first in your layout file and position the rest of the layout above the views with android:layout_above.
Have a look a RelativeLayout. Use this ViewGroup and add a Button inside it with alignParentBottom
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<Button
android:id="#+id/button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentBottom="true"
android:text="HORAIRE"
android:layout_margins="<your_margin_in_dp>" />
</RelativeLayout>
Make footerButton.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="HORAIRE"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
And add it in all your layout file like below line:
Android Activity_Layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Footer aligned to bottom -->
<include layout="#layout/footer" />
<!-- Content above footer -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content goes here"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Hope it will solve your problem
This is what I ended up doing. Thanks to everyone who posted, it helped me get in the right direction!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context="xxxx.MainActivity"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dernières nouvelles Twitter"
android:id="#+id/textView"
android:textStyle="bold"
android:textSize="17dp"
android:paddingLeft="8dp"
android:paddingTop="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp"
android:layout_alignParentTop="true"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView_tweets"
android:layout_above="#+id/buttonDisplay"
android:choiceMode="none"
android:paddingTop="25dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Horaire"
android:layout_margin="5dp"
android:id="#+id/buttonDisplay"
android:onClick="buttonGotoDisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
I designed a simple layout for my test App, a TextView, then a ImageView and a TextView. But the second TextView I want it scrollable (by touch).
I have searched and tried many solutions on the net but still can't make it work.
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scrollbars="vertical"
tools:context=".MainActivity" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/title"
android:textSize="40sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="#string/ada_lovelace"
android:paddingTop="8dp"
android:src="#drawable/ada_lovelace" />
<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="#+id/scroll1"
android:layout_below="#id/imageView1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="#string/hello_world"
android:textSize="22sp" />
</ScrollView>
</RelativeLayout>
Please help me.
You can use this link. And the format of using scrollview in xml is below:
<linearlayout>
<scrollview>
<linear>or <relativelayout>
</linear layout>
</scrollview>
</linear layout>.
Scrolling works only when a part of its child is not visible in the screen due to large size or large numbers
I had the same problem some weeks ago, and this was my solution:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/textview" />
</RelativeLayout>
</ScrollView>
But if there is not "enough" content in the TextView, it is not scrollable. Only if its more than your screen kann "capture".
Everything works fine after I re-import my project. I don't know what error is this but maybe it's because of eclipse faulty.
Instead of using ScrollView for your TextView, you can make you TextView scrollable using the following code.
<TextView
android:id="#+id/txtView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceSmall" />
And in you Java file use this code
txtView.setMovementMethod(new ScrollingMovementMethod());
Hope this will help.
You don't need a ScrollView for the TextView, TextView has the scrolling attribute.
Try setting it and see whether it works.
Set the ScrollView's height to 38dp.
Set the TextView's size to 40sp.
Then you can scroll the TextView.
Scrollable becomes only the part which is in between ScrollView
So if you want to scroll everything (And as I understood you do) you just need to change the sequence.
I also believe that ScrollView needs to be in layout and have a layout, so you need two layouts: one inside and one out side.Though I'm not sure about last sentence - I'm just starting to learn stuff
Here is your solution implement this code and run the code textview is scrollable.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="#string/ada_lovelace"
android:paddingTop="8dp"
android:src="#drawable/ada_lovelace" />
<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="#+id/scroll1"
android:layout_below="#id/imageView1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="#string/hello_world"
android:textSize="22sp" />
</RelativeLayout>
</ScrollView>
It should work please try
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding_bottom = "10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/textview" />
</ScrollView>
I just started my first android app following Big Nerd Ranch Android Programming book and in doing the first exercise it has me enter the following XML:
<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
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:padding="24dp"
android:text="#string/question_text"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button"
/>
</LinearLayout>
</LinearLayout>
However, when I switch back over to the graphical view it gives me a bunch of errors like:
"<LinearLayout>" does not set the required layout_width attribute:
(1) Set to "wrap_content"
(2) Set to "match_parent"
When I click to set it to one or the other it changes my XML to be:
<LinearLayout xmlns:android="http://schema.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android1:layout_width="match_parent"
android:layout_height="match_parent"
android1:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
Why is it insisting I use android1: and not accepting android: for any values?
Remove this line:
xmlns:android1="http://schemas.android.com/apk/res/android"
You have a typo in you xml namespace declaration:
xmlns:android="http://schema.android.com/apk/res/android"
should be
xmlns:android="http://schemas.android.com/apk/res/android"