Android :: Custom Widget - Attributes In The Layout Xml Files
Aug 6, 2010
I have defined custom views in the various layout .xml files. However, all the layouts are using the Linear Layout - put the content would vary.
I would like to create my own widget tag something like <com.mypackage.MyLinearLayout />, I would like to pass the layout as a param to the <com.mypackage.MyLinearLayout layout="@layout/simple.xml" />
How to define new attributes to the custom widgets ? Simply defining a getter/setter method would work or is there any other references.
View 2 Replies
May 3, 2009
I am writing a custom preference dialog derived from DialogPreference and I want to pass some custom attributes to the dialog through the preference's XML definition. Here's my preference.xml file:
CODE:...............
View 2 Replies
View Related
Nov 26, 2009
I have a simple horizontal linear_layout with bunch of image views in it. the trick is that the views have different widths, relative to the size of their parent (the linear layout). I set the layout's weightSum to a 100 and the layout_weight to let's say 10 of one view and 15 of the other, on so on. And it did not work. I also tired using float values setting the weightSum to 1.0 and the layout_weight of the image views to 0.2 and 0.3 and so on. But it didn't work either. I did search this group for any references to the weightSum but found nothing. Any ideas how to handle it?
View 5 Replies
View Related
Sep 14, 2010
Is there a way to specify a background in a layout based on OS version?:
android:background_1.5="@color/white"android:background_above_1.5="@drawable/mybackground"
I'm running into a problem where using a 9 png drawable for the background causes a stack overflow exception on a listview item (stack trace shows its related to a child TextView -> drawText()). The layout is simple:
<LinearLayout><ImageView /><TextView /></LinearLayout>
and the background works fine on 1.6 and above. It's just 1.5 that's having the issue. If I set the background to be a color, it works fine.
View 12 Replies
View Related
Mar 28, 2010
Looking in the android sdk folders, I've found a file called values/config.xml. This seems to be somewhere that you can define values for later use in layouts and animations.
Given the config.xml:
<resources>
<string name="config_somePadding">50dip</string>
</resources>
How would I reference this to use as the layout_height in a layout xml file?
@string/config_somePadding is actually the only one I've found that doesn't throw an error in Eclipse (even though there isn't a config_somePadding in values/strings.xml), but it appears to just put an empty string.
In the sdk, they use an integer for animation duration. They reference it like this: android:duration="@android:integer/config_longAnimTime". Is there a way to use values that aren't integers in the layout_height attribute?
View 1 Replies
View Related
Jun 16, 2009
If a RelativeLayout must be generated at run time, what are the equivalent API calls for the attributes set in the XML Layout editor? Take for example this very simple RelativeLayout that places the second ImageView to the right of the first ImageView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal" android:background="@drawable/ bg_sunrise"
android:layout_gravity="center" android:gravity="center">
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"></ ImageView>
<ImageView android:id="@+id/ImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/ ImageView01" android:src="@drawable/icon"></ImageView> </RelativeLayout>
Of the many, variations I tried, I had the most hope for this one, but it didn't work either:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams( new ViewGroup.LayoutParams (
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT ) );
ImageView imageView1 = new ImageView(this);
imageView1.setImageResource(R.drawable.icon);
imageView1.setAdjustViewBounds(true);
// set the ImageView bounds to match the Drawable's dimensions
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_TOP); layout.addView(imageView1, params1);
ImageView imageView2 = new ImageView(this); imageView2.setImageResource(R.drawable.icon);
imageView2.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.RIGHT_OF, imageView1.getId());
layout.addView(imageView2, params2); this.setContentView(layout); }
Can anyone offer the Java equivalent to the above XML? Can anyone explain why there is no attribute, getter/setter, or method for accessing the properties that can be set in XML? What is the most elegant solution for dynamically creating Layouts, Views, and other Resources on the Android platform when there is no Java programmatic equivalent?
View 11 Replies
View Related
Sep 26, 2010
I use custom xml attributes for preferences. The preferences are inflated from xml.I managed to create and read custom xml attributes for EditTextPreference, ListPreference and CheckBoxPreference by creating custom classes which inherit from the respective preference class.My problem is that I can't do this for the PreferenceScreen class, as it is a final class. So my question is: Is there any way I can read the custom attributes of a PreferenceScreen?
View 1 Replies
View Related
Jul 8, 2010
Having custom attribute (in attrs.xml) in library project leads to compilation fail of the project dependent of that library.Code...
How to avoid this except for no having custom attributes in library?
View 7 Replies
View Related
Apr 28, 2010
I have a layout issue. What I do is this:
CODE:..............
Class "NoteElement" extends TableRow. The 1st row just consists of a blank ImageView as a placeholder and an EditText to enter text. NoteElement's constructor looks like this:
CODE:..............
Method addTextField() specifies the attributes for the EditText widget:
CODE:..............
So far, so good. But my problem occurs as soon as the available space for the chars is depleted. The EditText does not resize itself but switches to a single line EditText.
I am desperatly looking for a way in which the EditText resizes itself in its height dynamically, being dependant on the inserted text length.
View 2 Replies
View Related
Apr 30, 2009
Is there a way define widget default values in the context of an application.
View 2 Replies
View Related
Aug 14, 2010
While developing for Android, I am unable to open more than one main.xml file in an Eclipse editor at a time.Each time I open one, it simply replaces the editor (tab) of the first main.xml with the new one, instead of opening a new tab - even if the contents of the existing tab were unsaved.Even stranger, I can open multiple main.xml files from different projects with no problems.This only happens when they're within the same project.
View 2 Replies
View Related
Sep 3, 2009
I am using eclipse 3.5 with the ADT plugin.when I view layout xml files, i get two tabs in the view the source code view and a graphical view.the graphical view almost never works for any of my layouts.it usually shows "NullPointerException: null" at the top and nothing else. when it does work, it often does not match what i get in the simulator or device.it seems like this thing simply is not ready for prime time; although the idea is very cool.has anyone else had much success with it?
View 5 Replies
View Related
Jul 9, 2010
I have created a simple class named Panel which extends the SurfaceView class and does some drawing in the onDraw method. When I use it from the code it works fine. For example this works as expected:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Panel(this)); ....
However when I try adding this component from an xml layout the program crashes:
XML file (main.xml):
<?xml version="1.0" encoding="utf-8"?> <org.anddev.Panel android:id="@+id/panel" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"/>
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);....
Error msg: Sorry!
The application Test (process org.anddev) has stopped unexpectedly. Pleas try again.
I can not figure out why the same class works when created in one way and doesn't work when created in another.
View 3 Replies
View Related
Feb 25, 2010
Is it possible to create a button with a custom xml layout? Now I want to use this on a button. Anyone know how I can do this? I was thinking if I had Button.java file that extended Button. And then setView( R. layout. mylayout.xml); but that was to easy, and it clearly not working
View 1 Replies
View Related
Nov 28, 2009
Currently, I am creating a custom View class (DrawView) that inherits the View class and adding to my activity programatically by using RelativeLayout and LaoutParams etc. But is there an easier way to do this by adding my DrawView to the layout XML file?
View 4 Replies
View Related
Jun 23, 2009
I've created a custom view via .xml file, and I wanted to add it as a a contentView to an alert Dialog usinf a dialogBuilder:
CODE:.................
The problem is...I can't get my view from my custom layout... I only have an id (int)...
I tried Resource.getLayout(int) => it returns an xmlParser... not very usefull ...
finally the solution I comes up is so disgusting ( it worked but ... let's have a look)
CODE:.......
How can I do that easily without using such a disgusting way... ?
View 2 Replies
View Related
Mar 9, 2010
I am trying to do is to embed a custom view in the default layout main.xml:
CODE:......
As you can see the class is called com.lam.customview.CustomDisplayView, with the id of custom_display_view1. now in the com.lam.customview.CustomDisplayView class, i want to use another layout called custom_display_view.xml because i don't want to programmatically create controls/widgets.
Custom_display_view.xml is just a button and an image, the content of which i want to change based on certain conditions:
CODE:..............
I tried to do:
1)
CODE:........
But got this error, "03-08 20:33:15.711: ERROR/onCreate(10879): Binary XML file line #8: Error inflating class java.lang.reflect.Constructor ".
2)
CODE:..........
But got this error, "03-08 20:28:47.401: ERROR/CustomDisplayView(10806): Resource ID #0x7f050002 type #0x12 is not valid "
Also, if i do it this way, as someone has suggested, it's not clear to me how the custom_display_view.xml is associated with the custom view class.
View 2 Replies
View Related
Jul 15, 2010
I've created my own view by creating a subclass of the SurfaceView class.
However I can't figure out how to add it from the xml layout file.
My current main.xml looks like this:
CODE:............
What have I missed?
My view looks like this
CODE:..............
And it works fine like this:
CODE:..................
But nothing happens when trying to use it from the xml.
View 1 Replies
View Related
Aug 16, 2010
I have a dialog with a custom layout, and I try to close it when I press a button:
private void showAboutDialog() {
dialog = new Dialog(MainMenu.this);
dialog.setContentView(R.layout.about_dialog);
dialog.setCancelable(true);
dialog.setTitle(R.string.about_title);
dialog.show();
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(R.id.layout_root));
Button closeButton = (Button) layout.findViewById(R.id.about_close_button);
closeButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { dialog.dismiss();
} } );
}
But it doesn't work.
View 1 Replies
View Related
Apr 29, 2010
The button doesn't show in this layout(code below),image and textview are shown. I tried using relative layout but that doesn't help either.
I'm testing it on 1.5 emulator.
CODE:..........................
View 1 Replies
View Related
Jul 26, 2010
I have a custom layout that draws a transparent rounded rectangle beneath its children. The problem is when I try to add it to my xml file, it doesn't show up. Also, when I try to add parameters to it (i.e. android:layout_width) the popup shows that none of them are available. The same thing happens to any child views I add. public class RoundRectLayout extends LinearLayout
{ private RectF shape;public RoundRectLayout(Context context)
{super(context);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
}public RoundRectLayout(Context context, AttributeSet attrs)
{ super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
} @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{shape = new RectF(0, 0, w - 5, h - 5);
super.onSizeChanged(w, h, oldw, oldh);
}@Override
protected void dispatchDraw(Canvas canvas)
Paint temp = new Paint();
temp.setAlpha(125);
canvas.drawRoundRect(shape, 10f, 10f, temp);
super.dispatchDraw(canvas);
View 2 Replies
View Related
Jun 13, 2010
I am having trouble getting my layout to give me result I need, I already tried many options and it seems that I'm doing something wrong or completely missing something.
I have a listview with a custom row layout I can't seem to working although it shouldn't be complex. I need of the list row to insist of:
Icon -- title text (bigger and bold) with a short multi line text under the title -- ImageButton
My problem in most of my tests is the icon to the right usually doesn't appear, I guess my center group grows and takes all the space of the button. My last failed attempt was with a Relative Layout, didn't have too much luck with a Linear Layout either.
Here is the row XML:
CODE:.........................
View 2 Replies
View Related
Aug 6, 2010
I am running a sqlite query and binding the returned data to a ListAdapter.
I have used the following example
ListActivity | Android Developers
However, having defined a seperate layout for the rows I cannot change the typeface for textview text1 to a custom one from assets
Here is the row layout
CODE:................
Here is the code from the andriod tutorial
CODE:............
We'll define a custom screen layout here (the one shown above), but typically, you could just use the standard ListActivity layout. setContentView(R.layout.custom_list_activity_view) ;
Query for all people contacts using the Contacts.People convenience class. Put a managed wrapper around the retrieved cursor so we don't have to worry about requerying or closing it as the activity changes state.
CODE:................
Now create a new list adapter bound to the cursor. SimpleListAdapter is designed for binding to a Cursor.
CODE:................
Specify the row template to use (here, two columns bound to the two retrieved cursor rows). mCursor, // Pass in the cursor to bind tonew String[]{People.NAME, People.COMPANY}, // Array of cursor columns to bind to. new int[] {android.R.id.text1, android.R.id.text2}); // Parallel array of which template objects to bind to those columns.
CODE:................
View 2 Replies
View Related
Aug 8, 2010
I have created a custom list item layout just like in this article http://developer.android.com/resources/articles/layout-tricks-efficie....
Each list item has icon, title and summary.
I would like to declare an xml resource that would provide data for that list. Just like you use <string-array> to populate the list using ArrayAdapter<String>.
The simple ArrayAdapter<String> can be populated from:
CODE:..........
I need each <item> to have icon, title and summary. Somewhat similar to:
CODE:..........
I would use <menu> but menu doesn't have summary if I'm not mistaken.
View 10 Replies
View Related
Jul 29, 2010
I am trying to refer to a custom View in the helloWorld XML layout but I get the following exception:
Error inflating class acme.my.MyTextView.
However, I am able to instantiate the view and add it to the main content view manually. The custom View is built from it's own XML layout. How do I get this to work?
CODE:....................
View 1 Replies
View Related
Oct 12, 2010
I'm experimenting with the Android platform, and I'm beginning to love it, but right now I'm stuck, at this cursor/list adapter problem-thing.
The thing is, that I request a function, returning a data object, with several properties I'd like to map to different TextView's.
My list_item.xml
CODE:...........
So what I would like to do is: Map a property of an array of objects to several fields in the file.
View 1 Replies
View Related
May 21, 2010
How to I tell my own custom Spinner Layout to use my Theme? code...
View 2 Replies
View Related
Aug 13, 2010
Im creating a custom layout and I want to use the text declared in the layout.xml file in my layout.
Like when I create a TextView in XML and set android:text=@string/text1 when I run the app text view automatically loads the text from android:text. So how can I access attributes declared in the layout XML file in my custom component.
View 2 Replies
View Related
Aug 9, 2010
I understand how to create a custom Android control, and I believe I understand how to pull attributes for it from the Xml layout. I don't know, however, how to get any children elements from it. Here's a visual example of what I'm trying to accomplish: public class Menu extends LinearLayout. When my Menu is created, how do I get references to the two MenuItems. Code...
View 2 Replies
View Related
Jul 30, 2010
I have a custom View that I'd like to specify the layout of in an XML file rather than through code, is there anyway I can take an Android XML layout file and use it to flush out my custom View's content? I know it can be done in an Activity via the setContentView method, but there doesn't seem to be a similar method for Views.
View 1 Replies
View Related