Missing resource error, in Android - android

Thank you everyone who posted an answer, I looked over most of them and they all seem to work! Sorry if I didn't mark your's the answer since I could only mark one. However all methods below worked for me. Much appreciated.
Hi just a couple of things to know:
I created a new activity, very simple. Basically the function is to press the button on the MainActivity page which will redirect the user to a new page called display. Everything seems to be working fine except for two errors I keep on getting. The android:id="#+id/" and android:layout_below="#+id/" return that they are missing resource names.
Here is my code:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="#string/welcome_screen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/g_button"
android:id="#+id/g_button"
android:layout_marginTop="121dp"
android:layout_below="#+id/"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onButtonClick" />
</RelativeLayout>
Any help would be much appreciated.

You have to give proper id to textview like below code
<TextView android:text="#string/welcome_screen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/myText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/g_button"
android:id="#+id/g_button"
android:layout_marginTop="121dp"
android:layout_below="#+id/myText"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onButtonClick" />

Replace your layout like this
<TextView android:text="#string/welcome_screen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_temp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/g_button"
android:id="#+id/g_button"
android:layout_marginTop="121dp"
android:layout_below="#+id/tv_temp"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onButtonClick" />
</RelativeLayout>

you actually describing the id tag and not giving the id to your views.Give your views some id.for eg :-
<TextView android:text="#string/welcome_screen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textAbc" //id cannot be left blank
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/g_button"
android:id="#+id/g_button"
android:layout_marginTop="121dp"
android:layout_below="#+id/myText"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onButtonClick" />

You need to have an ID name after the identifier, for example
android:layout_below="#+id/textview1"
android:layout_below="#+id/button1"
That ID is used to reference the View element from the code. For more details, see
http://developer.android.com/guide/topics/ui/declaring-layout.html

Cause
The layout has a TextView and below it a Button (atleast you want that), in the button you have layout_below which expects an id of the widget you want it to be below. But in your case you did not specify one. So you are getting this error.
Solution
Replace your xml with this the xml below.
<TextView android:text="#string/welcome_screen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/top"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/g_button"
android:id="#+id/below"
android:layout_marginTop="121dp"
android:layout_below="#+id/top"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onButtonClick" />

Try this code
<TextView android:text="#string/welcome_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textview"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/g_button"
android:id="#+id/g_button"
android:layout_below="#+id/textview"
android:layout_marginTop="121dp"
android:layout_centerHorizontal="true"
android:clickable="true"
android:onClick="onButtonClick" />

android:id="#+id/textview"
You can give id manually. If you want

android:id="#+id/"
android:layout_below="#+id/"
Remove them your not doing anything with that attributes :
ID
Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute. This is an XML attribute common to all View objects (defined by the View class) and you will use it very often. The syntax for an ID, inside an XML tag is:
eg android:id="#+id/my_button"
android:layout_below
Positions the top edge of this view below the given anchor view ID. Accommodates top margin of this view and bottom margin of anchor view.
Must be a reference to another resource, in the form "#[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".
This corresponds to the global attribute resource symbol layout_below.
android:layout_below="#+id/myText"

In your xml file- the code for TextView , u have to give a name/id to it like below:
<TextView android:text="#string/welcome_screen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtVw1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="#000000"/>

Related

Android (Xamarin) padding in textview

I'm implementing an EULA with a checkbox, where part of the text is clickable. Through googling and from other answered questions here, I've used a checkbox with no text and a separate textview for the text, which in the C# code uses a SpannableString and ClickableSpan.
However, I'm having some problems with the layout of the checkbox and textview. Here is what the layout looks like now:
I want to get the one on top to look like the one below
As can be seen, there's a large unknown padding on the left and right of the textview even though the padding is explicitly set to 0. Here is the xml code:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/registerMobileField"
android:layout_marginTop="27dp"
android:layout_centerHorizontal="true">
<CheckBox
android:id="#+id/pdpaChkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0"
android:text=""
android:scaleX="0.80"
android:scaleY="0.80" />
<TextView
android:id="#+id/pdpaText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/pdpaChkbox"
android:layout_centerVertical="true"
android:padding="0"
android:textColor="#color/dark_blue"
android:text="#string/pdpa"
android:scaleX="0.80"
android:scaleY="0.80" />
</RelativeLayout>
<CheckBox
android:id="#+id/pdpaChkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/registerMobileField"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:textColor="#color/dark_blue"
android:text="#string/pdpa"
android:scaleX="0.80"
android:scaleY="0.80" />
Any help would be greatly appreciated!
This is not unknown padding this is scaleX and scaleY property you have given to you that you have given CheckBox and TextView. just remove these properties from your CheckBox and TextView and give it to the RelativeLayout then your both case will same as follows.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/registerMobileField"
android:layout_marginTop="27dp"
android:scaleX="0.80"
android:scaleY="0.80"
android:layout_centerHorizontal="true">
<CheckBox
android:id="#+id/pdpaChkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/pdpaText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/dark_blue"
android:layout_toRightOf="#id/pdpaChkbox"
android:layout_centerVertical="true"
android:text="#string/app_name"
/>
</RelativeLayout>
<CheckBox
android:id="#+id/pdpaChkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:textColor="#color/dark_blue"
android:layout_below="#id/registerMobileField"
android:text="#string/app_name"
android:scaleX="0.80"
android:scaleY="0.80" />
I hope its work for you

Android layout_toLeftOf not working

I've searched quite a lot here and have tried to provide information about how to align the children objects inside my relative layout, however one of them doesn't display.
This is my code:
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#id/textView1"
android:layout_below="#id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="example"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/textView2"
android:layout_alignBottom="#id/textView2"
android:text="example" />
</RelativeLayout>
TextView3 doesn't appear at all. It looks like there is a missing or conflicting rule, but I can't figure out which one.
Go ahead and give this a try, works for me.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="example"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:text="example"
/>
</RelativeLayout>
textView2 is aligned to the left. If you align textView3 to the left of a left object it's going to be off the screen
Your code does not provide the code for textView1, but if I were to assume that your textView1 were to be on the top left side of the screen, then if you have this line for your inner RelativeLayout:
android:layout_alignLeft="#id/textView1"
textView2 would be aligned to textView1, therefore if you added textView3 was added and you did:
android:layout_toLeftOf="#id/textView2"
then it would appear off the screen to the left.
What I watch here for example using Relative Layout ,you need to be specific, if you wish to locate to the right of editTextNumberPeriods in this case, also you need to instruct .xml where is textView2, in this case it is below btn18, I meant it is not enough to instruct .xml if it is right or left. I tested it, it works perfectly.
<TextView
**android:id="#+id/btn18"**
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:gravity="center"
android:textAllCaps="false"
android:layout_centerHorizontal="true"
android:layout_below="#id/btn19"
android:text="Please enter numbers of periods." />
<EditText
**`android:id="#+id/editTextNumberPeriods"`**
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btn18"
android:cursorVisible="true"
android:focusable="true"
android:fontFamily="sans-serif"
android:layout_centerHorizontal="true"
android:ems="10"
android:gravity="center"
android:background="#68DBFA"
android:hint="numbers of periods"
android:textColorHint="#color/white"
android:inputType="number"
android:selectAllOnFocus="true"
android:textAllCaps="false"
android:textColor="#7C1616" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:layout_below="#id/btn18"
android:layout_toRightOf="#id/editTextNumberPeriods"**
android:text="TextView" />

Prevent views from overlapping in RelativeLayout

I'm trying to develop an android application, but I'm having some problems with the GUI design. The following part of screenshot is my problem (red and blue lines were generated by Android debug options).
This is the code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/caption"
android:layout_below="#+id/caption" >
<ImageButton
android:id="#+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="#drawable/content_edit"
style="?android:attr/borderlessButtonStyle" />
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/num_placeholder"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
As you can see, the TextView myText overlaps the ImageButton button_edit.
A simple solution would be to use a LinearLayout instead of a RelativeLayout. The problem is that:
I need the edit button on the right
I need the text to fill the rest of the layout (at the left of edit button obviously)
I also tried to set myText's layout_width to 'fill_parent', but it fill the entire rest of the screen at the left of the edit button.
The expected behavior would be myText to increase its height (becoming a two-lines TextView) instead of overlapping 'button_edit'
Can anyone help me? Thanks
use layout_toLeftOf in TextView layout
like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/caption"
android:layout_below="#+id/caption" >
<ImageButton
android:id="#+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="#drawable/content_edit"
style="?android:attr/borderlessButtonStyle" />
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/num_placeholder"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_toLeftOf="#+id/button_edit" />
Another way of doing is to use android:layout_toEndOf attribute
<ImageButton
android:id="#+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="#drawable/content_edit"
style="?android:attr/borderlessButtonStyle"
android:layout_toEndOf="#+id/myText" />
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/num_placeholder"
android:textAppearance="?android:attr/textAppearanceLarge" />

Android XML ImageView below TextView but needs to align bottom with textView

So My text View has to be drawn over the image view, so its defined in xml like this:
<ImageView
android:id="#+id/chatBalloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/chatItemProfPic"
android:scaleType="fitXY"
android:src="#drawable/chat_bar_user" />
<TextView
android:id="#+id/userText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#+id/chatItemProfPic"
android:text="username"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
but i because the textView can contain multiline text, i need to have the imageView increase its height accordingly. It would be accomplished by adding this rule:
android:layout_alignBottom="idOfText"
but because the textView hasnt been defined at that part, the app crashes. I get the same when trying to do it from code by addRule in the LayoutParams because i call it in onCreate, before the view has been drawn.
Any ideas how to bypass this?
SOLVED:
Final xml:
<ImageView
android:id="#+id/chatBalloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/chatItemProfPic"
android:scaleType="fitXY"
android:layout_alignBottom="#+id/userText"
android:src="#drawable/chat_bar_user" />
<TextView
android:id="#id/userText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#+id/chatItemProfPic"
android:text="username"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
You use
android:layout_alignBottom="#+id/idOfText"
when you first make a reference to a particular id. Note the "+" which is adding the id to the list of resource identifiers.
Then, you can assign an existing id to a widget without using the "+", as follows:
android:id="#id/idOfText"
after. It's typical to create the id when we're assigning it, which is why you only really need to care about the presence of the "+" in relative layouts.
In your specific case:
<ImageView
android:id="#+id/chatBalloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#id/chatItemProfPic"
android:layout_alignBottom="#+id/userText"
android:scaleType="fitXY"
android:src="#drawable/chat_bar_user" />
<TextView
android:id="#id/userText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="#id/chatItemProfPic"
android:text="username"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
You should have set the ID of the profile pic widget using: android:id = "#+id/chatItemProfPic" assuming that you are declaring the widget before any references to it. Otherwise, similarly, use "+" for the first reference, and then assign the ID when you declare the widget without the "+".
why dont put that image like textview background.?
or something like:
<RelativeLayout
android:id="#+id/Rlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="35dp" >
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/img" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="lorem ipsum"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="#dimen/dimension" />
</RelativeLayout>
in relative layout you could easily put text right over imageview

The primitive type int of R.layout does not have a field

I am trying to setup an activity and when I try to assign some of my views to names in the .java file its telling that R.layout.bathing does not have field datePicker1 and it does have it. Here is my two code snippets. What should I change to get this to work?
bathing.java
setContentView(R.layout.bathing);
setTitle("Please Select Bathing Options");
bathdate = (DatePicker)findViewById(R.layout.bathing.datePicker1);
bathtime = (TimePicker)findViewById(R.layout.bathing.timePicker1);
add = (Button)findViewById(R.layout.bathing.button1);
bathing.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/bath_tracking"
android:textAppearance="?android:attr/textAppearanceLarge" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView3"
android:layout_marginTop="16dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/datePicker1"
android:layout_marginTop="51dp"
android:text="#string/date"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/datePicker1"
android:layout_below="#+id/datePicker1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/timePicker1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="50dp"
android:text="#string/time"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/timePicker1"
android:orientation="vertical" >
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Yes" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/radioGroup1"
android:layout_below="#+id/radioGroup1"
android:text="#string/No" />
</RadioGroup>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/radioGroup1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="36dp"
android:text="#string/hair"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/timePicker1"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroup1"
android:inputType="textMultiLine" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:text="#string/Add"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentLeft="true"
android:text="#string/comment"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
You have to access view objects via their id, instead of
bathdate = (DatePicker)findViewById(R.layout.bathing.datePicker1);
use
bathdate = (DatePicker)findViewById(R.id.datePicker1);
and so on. IDs are global, they are not specific to a certain layout.
That doesn't neccessarily mean that each view has to have an unique name. The most important thing to know is that findViewById() only searches in the view hierachy of the current activity (you can try this by calling it before setContentView() - it will always return null). In the end it means that IDs should be unique in a single layout file.
There is no problem in having the same id in multiple layouts. Often it's even useful. Consider having an activity with a normal layout in res/layout/main.xml and a different layout for the landscape format in res/layout-land/main.xml. Android will manage these layouts for you. If you give views with identical purposes a different, unique id, you would have to do something along this in your code (pseudocode example):
if(layout == portrait)
view = findViewById(R.id.viewid_portrait);
else if(layout == landscape)
view = findViewById(R.id.viewid_landscape);
If both have the same ID you won't have a conflict, but can access both via a single line call of findViewById().

Categories

Resources