Android :: How To Change Custom Component Height Programmatically?

Dec 9, 2009

I've prepared custom component based on LinearLayout. Whole component is defined in XML. Currently to use it you have to write:
<com.xxx.android.components.TopMenu
android:layout_width="fill_parent"
android:layout_height="44dp" />

Is it possible to set width and height in the java constructor? So it would be possible to write just:
<com.xxx.android.components.TopMenu />
I've tried to modify and set LayoutParams, but it didn't work for me.

Android :: How to Change Custom Component Height Programmatically?


Android :: Change Width - Height Of A Widget Programmatically

Jul 16, 2010

What's the best way to change width/height of a widget (I mean, a UI widget, subclass of android.view.View) programmatically?

Doing something like this works, but it doesn't seem quite right:

CODE:....................

View 2 Replies View Related

Android : Change Custom SurfaceView Width And Height

Nov 2, 2010

How can i change custom SurfaceView width and height. is this possible?

View 1 Replies View Related

Android :: Possible To Setup Focus To A Component Programmatically?

Mar 16, 2009

Wondering if we have few buttons on a LinearLayout, is it possible to set focus to a button programmatically?

View 4 Replies View Related

Android :: How Can Find Out Height Of Status Bar Programmatically?

Apr 29, 2009

How can I find out the height of the status bar programatically?

View 2 Replies View Related

Android :: XML Layout Of Custom Component

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

Android :: Create Custom Component Using Inflate

Mar 29, 2010

I'm trying to create a component using an xml layout file. I defined a layout with some custom attributes. This layout is inflated when user add it inside another layout. My problem is I don't know the parent, so I pass null for the parent viewgroup when I call inflate method. I think that's the reason why I see anything in my view. Do you know how can I do (I don't want to redefine onDraw method because I use existing component). Below my xml layout and my custom class.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@+id/img_btn_option" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/txt_btn_option" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@id/img_btn_option"
android:textColor="@color/font_white" android:textStyle="bold"/>
</RelativeLayout> public class ButtonOptionsView extends View {
public ButtonOptionsView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater li =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout vg =(RelativeLayout)li.inflate(R.layout.button_option, null);
TypedArray ta = getContext().obtainStyledAttributes(attrs,R.styleable.ButtonOption);
((ImageView)vg.findViewById(R.id.img_btn_option)).setImageResource(ta.getResourceId(R.styleable.ButtonOption_image,0));
((TextView)vg.findViewById(R.id.txt_btn_option)).setText(ta.getResourceId(R.styleable.ButtonOption_text,0));}

View 4 Replies View Related

Android :: Custom Component ImageView Override

Dec 8, 2009

I've made a little test component that overrides ImageView, called myImageView, and prints some text and an arrayList of Doubles over whatever image is specified in the related xml. However, right now, the text and Doubles that are drawn over the image are defined within the myImageView class. Is there a way to pass the data from the main onCreate function to the myImageView class before the layout is drawn?

I'm new to OO programming, but based on my understanding of this:
http://developer.android.com/guide/topics/ui/custom-components.html
It's possible because ImageView is just like any other class. This leaves me with two initial guesses:
1. I could generate my test data in the main onCreate, and store it in the array's xml file, and then read that xml file with myImageView,
OR
2. I could extend view instead of ImageView, but because of my new- ness, then I would lose the ability to use it in an xml layout sense - and that's what I really want.

View 2 Replies View Related

Android :: Custom Compound Component Rare Exception

Aug 16, 2009

I've created custom compound component and observe very strange exception (google says nothing about it). Custom component rare exception: Parser is not a BridgeXmlBlockParser!

It is very simple:
public class MyTabber extends LinearLayout {
.. public MyTabber(Context context) { super(context);
Init(context); }

View 2 Replies View Related

Android :: Views In Custom Compound Component Not Inflated

Jun 12, 2010

I have made a Custom Component in XML, consisting of a button with an imageview stacked on top of it:

<myapp.widget.ClearableCaptionedButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/ccbutton_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:drawable/edit_text"/>
<ImageView
android:id="@+id/ccbutton_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_alignRight="@id/ccbutton_button"
android:layout_alignTop="@id/ccbutton_button"
android:layout_alignBottom="@id/ccbutton_button"/>
</myapp.widget.ClearableCaptionedButton>

Extract of java source code:
public class ClearableCaptionedButton extends RelativeLayout implements OnClickListener {
...
public ClearableCaptionedButton(Context context, AttributeSet attrs) { super(context, attrs);
// some stuff that works fine
} ..
protected void onFinishInflate() { super.onFinishInflate();
mButton = (Button) findViewById(R.id.ccbutton_button);
mClear = (ImageView) findViewById(R.id.ccbutton_clear);
mButton.setText(""); // error here: mButton == null
}

My problem is similar to this one. When I try to find the views inside the custom compound, findViewById returns null. But, as you can see, i already added super(context, attrs); to the constructor. I am using the custom component directly in xml layout, like this:

<LinearLayout>
<!-- some stuff -->
<myapp.widget.ClearableCaptionedButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:caption="to"/>
</LinearLayout>

View 1 Replies View Related

Android :: Creating Custom Component Which Supports Voice Recognition

Jun 11, 2010

I'd like to create a custom component which supports voice recognition. (Custom Component which displays voice recognition button if available). It will primarily be an extended EditText which should show the microphone button for voice recognition if it is available. I wanted to to look at the search app-widget on the homescreen but I don't find it in the source. This is intended to use the voice recognition as some sort of dictation device, i.e. the user does not have to type but use his voice instead. So could anyone please point me in some direction?

View 1 Replies View Related

Android :: Expanding ListView Custom Component With Button Click

Nov 5, 2010

I'm developing a small application in with a list view filled with a compound component. This component has two text view and one button inside. One of the text view is invisible and when the button is clicked it should appear. I can show the list but i can't make the textview visible when the button is clicked. Here is the xml of the component: And this is the ArrayAdapter that fills the list:

public class AddressAdapter extends ArrayAdapter { int resource;
RelativeLayout placeView;
EditText addressText;
public AddressAdapter(Context _context, int _resource, List _items) {
super(_context, _resource, _items);
resource = _resource;
} private OnClickListener buttonClick = new OnClickListener() {
public void onClick (View v) {
int i = placeView.findViewById(R.id.stub_import).getVisibility();
visibility(i);
} };
private void visibility(int i) {
// TODO Auto-generated method stub switch(i) {
case(View.GONE): { addressText.setVisibility(View.VISIBLE);
} case(View.VISIBLE): { addressText.setVisibility(View.GONE);
} } }
@Override public View getView(int position, View convertView, ViewGroup parent) {
Item item = getItem(position);
String name = item.getName();
String address = item.getAddress();
if (convertView == null) {
placeView = new RelativeLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, placeView, true);
} else { placeView = (RelativeLayout) convertView;
} TextView nameText = (TextView)placeView.findViewById(R.id.placeNamwView);
Button button = (Button)placeView.findViewById(R.id.Button01);
addressText = (EditText)placeView.findViewById(R.id.placeAddressText);
button.setOnClickListener(buttonClick);
nameText.setText(name);
addressText.setText(address);
return placeView;
} }

View 2 Replies View Related

Android :: Including Custom Component / View No Longer Shows Up

Oct 29, 2009

The app I'm working on has 4 tabs, 3 of which share many features, including a navigation bar a the bottom with Back, Edit, and Map buttons. There is exactly the same xml in all 3 layouts, so I'm trying to DRY this out by extracting that xml into a separate component, including it, and then going from there. Previously I had:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/showedit_toolbar" style="@style/showItemToolbar">
<ImageButton android:id="@+id/show_person_back_button"
style="@style/blackToolbarButton"
android:src="@drawable/left_white_arrow"
android:layout_alignParentLeft="true"/>
<Button android:id="@+id/show_person_map_button"
style="@style/blackToolbarButton"
android:text="map" android:layout_alignParentRight="true"/>
<Button android:id="@+id/show_person_edit_button"
style="@style/blackToolbarButton"
android:text="edit" android:layout_toLeftOf="@id/show_person_map_button"/>
</RelativeLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="@id/showedit_toolbar"
style="@style/CoinLightTheme">
// Lots more layout omitted

I extracted out the bit that's repeated into an xml file called show_toolbar.xml, changing the names of variables to make it more generic across the 3 views
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/show_toolbar" style="@style/showItemToolbar">
<ImageButton style="@style/blackToolbarButton"
android:src="@drawable/left_white_arrow"
android:layout_alignParentLeft="true"
android:id="@+id/show_back_button"/>
<Button android:id="@+id/show_map_button"
style="@style/blackToolbarButton"
android:text="map" android:layout_alignParentRight="true"/>
<Button android:id="@+id/show_edit_button" style="@style/blackToolbarButton"
android:text="edit" android:layout_toLeftOf="@id/show_map_button"/>
</RelativeLayout>

Then from within my original layout file, I replaced that big block of code with
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<include android:id="@+id/show_toolbar" layout="@layout/show_toolbar"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_above="@id/showedit_toolbar" style="@style/CoinLightTheme">

Now, the problem is that the view no longer shows up. Including Custom component causes it to be hidden behind main viewI can still click the buttons and they respond (i.e. if I click in the corner where the button should be, it still works), but I cannot see the buttons or bar onto which they were drawn. I cannot find very good documentation on how Include is supposed to work, so perhaps I am using it incorrectly.

View 1 Replies View Related

Android :: Find View Returns Null For Custom Component In Layout

Nov 7, 2009

I have a res/layout/main.xml including these elements and others:

<some.package.MyCustomView android:id="@+id/foo" (some other params) />
<TextView android:id="@+id/boring" (some other params) />
In my Activity's onCreate, I do this:
setContentView(R.layout.main);
(TextView) boring = findViewById(R.id.boring);
// ...find other elements...
MyCustomView foo = (MyCustomView) findViewById(R.id.foo);
if (foo == null) { Log.d(TAG, "epic fail"); }

The other elements are found successfully, but foo comes back null. MyCustomView has a constructor MyCustomView(Context c, AttributeSet a) and a Log.d(...) at the end of that constructor appears successfully in logcat just before the "epic fail".
findViewById() returns null for custom component in layout XML, not for other components. Why is foo null?

View 2 Replies View Related

Android :: Custom Adapter - How To Set Row Height?

Jan 31, 2010

How do I set row height if text of some rows more than one line when writing custom ArrayAdapter?

View 4 Replies View Related

Android :: Height Of Custom View?

Oct 21, 2009

I have a custom class that extends view class. Now this custom view is set in the listadapter that extends baseadapter. Along with the custom view I have a TextView in the list.

So the xml i inflate for list view is

CODE:......

the customview sets a rounded rectangle behind the text in TextView. Now The height of the textview vary as per its content. So I want the height of the customview also vary as per the height of TextView.

View 2 Replies View Related

Android : Get A Custom View's Height And Width?

Nov 2, 2010

How do I use getMeasuredWidth() and getMeasuredHeight? It always returns 0. what is the difference between this and getHeight() and getWidth()?

View 3 Replies View Related

Using HTML Component How To Change Color Of Font In Textview

Nov 25, 2011

Using HTML component , it is possible to change the font size and displayed the string in textview. Like that if there is any option to change the font color using HTML component or XML component?

View 1 Replies View Related

Android :: How To Change Height Of View

Nov 10, 2009

All works fine, however I want the gameboard to appear as square. So I need to resize the board at runtime to put it in the center of the screen and make it square. I tried many options without success.

View 2 Replies View Related

Android : Change The Height Of A ProgressBar

Apr 29, 2010

I was wondering what is the easiest way to change the height of a ProgressBar in Android?

View 1 Replies View Related

Android : Change The Height Of A Row In A Listview

Sep 28, 2010

I want when a user clicks a row, that row grows to show more items with an scale animation, but I can't find how can I do that.

First: I don't know how can I change a height row at runtime. I've tried making the items visible, but this didn't work even if I inflate with another XML layout.

Second: If I achieve the first one, I think I could make the scale animation.

View 1 Replies View Related

Android : Change The Listview Row Height

Nov 8, 2010

How to change the listview row height?

View 2 Replies View Related

Android : Change Height Of Notification

Mar 10, 2009

Is there any way to change the height of the "extended" notification (i.e. the contentView in the Notification)? It seems like I get the standard two lines no matter what... I'm thinking I've missed something, but ...

View 8 Replies View Related

Android :: Android - Writing Custom (Compound) Component

Sep 25, 2009

The Android app I'm currently developing has a main activity that has grown quite large. This is mainly because it contains a TabWidget with 3 tabs. Each tab has quite a few components. The activity has to control of all those components at once. So I think you can imagine that this Activity has like 20 fields (a field for almost every component). Also it contains a lot of logic (click listeners, logic to fill lists, etc). What I normally do in component based frameworks is to split everything up into custom components. Each custom component would then have a clear responsibility. It would contain it's own set of components and all other logic related to that component.

I tried to figure out how this can be done, and I found something in the Android documentation what they like to call a "Compound Control".
(See http://developer.android.com/guide/topics/ui/custom-components.html and scroll to the "Compound Controls" section) I would like to create such a component based on an XML file defining the view structure.

In the documentation it says:
Note that just like with an Activity, you can use either the declarative (XML-based) approach to creating the contained components, or you can nest them programmatically from your code. Well, that's good news! The XML-based approach is exactly what I want! But it doesn't say how to do it, except that it is "like with an Activity". But what I do in an Activity is call setContentView(...) to inflate the views from XML. That method is not available if you for example subclass LinearLayout. So I tried to inflate the XML manually like this:

public class MyCompoundComponent extends LinearLayout {
public MyCompoundComponent(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_layout, this);
} }

This works, except for the fact that the XML I'm loading has LinearLayout declared as the root element. This results in the inflated LinearLayout being a child of MyCompoundComponent which itself already is a LinearLayout!! So now we have a redundant LinearLayout in between MyCompoundComponent and the views it actually needs. Can somebody please provide me with a better way to approach this, avoiding having a redundant LinearLayout instantiated?

View 1 Replies View Related

Android :: Android - Showing Dialog From Custom Component

Jun 15, 2010

I am writing a custom component (derived from a relative layout) which has to show a dialog. Is there a way to do this using callbacks like oncreatedialog or onpreparedialog? if not: if i have to create the dialog outside oncreatedialog, i have to "attach it to an Activity with setOwnerActivity(Activity)". How can the custom component access the activity it is used in, when it is used in the activity's xml-layout and not created from code?

View 1 Replies View Related

Android :: Android - Defining Custom Component Layouts In XML

Oct 5, 2010

I'm reading the android developer docs on creating custom components and one thing that's unclear, is whether you can define the layout of your component using xml and then reuse that across class libraries. like, say for instance, I want to create a class library called myComponents, and in there i want to have myTehAwesumsWidget or whatever, and i want the layout to be defined in xml, can i include that xml in the referenced class library?

View 1 Replies View Related

Android :: Configuration Change - Width And Height

Jul 25, 2010

What happens to the width and height params declared in LayoutParams on configuration change? E.g. if I have an ImageView declared with,
new LinearLayout.LayoutParams(30, 40);
On Configuration Change, does the width become 40 and height 30?

View 1 Replies View Related

Android :: Change Height Of EditText And Button?

Nov 10, 2010

I have this EditText and Button, and I have to reduce its height. I try with android:height="10px" but it doesn't work. Btw android:width="180px" works OK, then I don't know why I can't adjust the height.

Here is the code:....................

View 4 Replies View Related

Android :: Can't Change Width / Height At Runtime - Way To Do

Aug 26, 2010

I want to have a grid with 3 columns and 3 rows and an image button in each cell (center of cell)

i tried with gridview but i can't fix the number of rows
i tried with a tablelayout and 3 tablerows, but i can't change width/height at runtime.

View 3 Replies View Related

Android : Change The Height Of A Webview On Runtime

Feb 26, 2010

I have a webview and a table containing 4 buttons. I have set the height of the webview to 400px, so that the buttons are displayed at the bottom of the screen, in portrait mode. My problem is, when changed to landscape mode the buttons are not visible. So I need to change the height of the webview on runtime, when orientation is changed. Do anybody know how to achieve this? I am able to capture the orientation change, using 'onConfigurationChanged' function.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved