Error in implementing a custom view in android: - android

I'm trying to implement a custom View in my application. I went over this page:
http://developer.android.com/training/custom-views/index.html
and I have created the following:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/leftMenu"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:background="#drawable/left_menu_background"
android:orientation="vertical"
android:visibility="gone" >
<ImageButton
android:layout_width="fill_parent"
android:layout_height="52dp"
android:background="#drawable/left_menu_close_button"
android:onClick="showLeftMenu" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/left_menu_separator" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/left_menu_buttons_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/left_menu_data_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/left_menu_button_transparent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:onClick="showSelectTab">
<ImageButton
android:id="#+id/left_menu_data_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/transparent_rectangle"
android:scaleType="fitXY"
android:src="#drawable/folder"
android:onClick="showSelectTab"/>
<TextView
android:id="#+id/left_menu_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Data"
android:textColor="#color/my_white"
android:onClick="showSelectTab"/>
</LinearLayout>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/left_menu_separator" />
<LinearLayout
android:id="#+id/left_menu_settings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/transparent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:onClick="showSettingsPopup">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/transparent_rectangle"
android:scaleType="fitXY"
android:src="#drawable/settings"
android:onClick="showSettingsPopup"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Settings"
android:textColor="#color/my_white"
android:onClick="showSettingsPopup">
</TextView>
</LinearLayout>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/left_menu_separator" />
</LinearLayout>
</ScrollView>
and those classes:
AppViewLinearLayout:
package com.emildesign.sgreportmanager.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
public class AppViewLinearLayout extends LinearLayout {
public AppViewLinearLayout(Context context, AttributeSet attrs, int layoutResource)
{
super(context, attrs);
if (isInEditMode())
return;
View view = LayoutInflater.from(context).inflate(layoutResource, null);
addView(view);
}
}
and: LeftSideMenu:
package com.emildesign.sgreportmanager.ui;
import com.emildesign.sgreportmanager.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
public class LeftSideMenu extends AppViewLinearLayout
{
private LeftSideMenuClickListener mListener;
public LeftSideMenu(Context context, AttributeSet attrs, int layoutResource)
{
super(context, attrs, layoutResource);
findViewById(R.id.left_menu_data).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (mListener != null)
mListener.dataOnClick(v);
}
});
findViewById(R.id.left_menu_settings).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (mListener != null)
mListener.settingsOnClick(v);
}
});
}
public interface LeftSideMenuClickListener {
void dataOnClick(View v);
void settingsOnClick(View v);
}
}
Now I try to add it to my main layout like this:
<FrameLayout 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"
tools:context=".LoginScrActivity" >
<com.emildesign.sgreportmanager.ui.LeftSideMenu
android:id="#+id/leftSideMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
....
and for some reason I receive this in the logcat:
E/AndroidRuntime( 1034): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{com.emildesign.sgreportmanager/com.emildesign.sgreportmanager.activi
ties.ReportsTableActivity}: android.view.InflateException: Binary XML file line
#10: Error inflating class com.emildesign.sgreportmanager.ui.LeftSideMenu
UPDATE:
I made the following change, in LeftSideMenu:
public LeftSideMenu(Context context, AttributeSet attrs)
{
super(context, attrs, R.layout.left_menu);
.....
The error was gone, but I still can see my custom layout.
Hirarchy Viewer:
What am I doing wrong?
Any help would be appreciated.
Thanks.

Add this constructor:
public LeftSideMenu (Context context, AttributeSet attrs) {...}

Related

layout_weight property is ignored in Custom Views

I tried implementing a custom view and put it in an expandable card view, which is contained inside a RecyclerView. At the start, I open it and it looks quite nice.
Before scroll
But then, I leave it opened and scroll to the bottom of the RecyclerView. When I scroll back to the item, close it and then open it again, the layout is broken.After scroll
Below is the code of the custom view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="60dp" android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<View
android:layout_width="#dimen/session_padding_left"
android:layout_height="#dimen/session_padding_left"></View>
<TextView
android:id = "#+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#color/lightGray"
android:gravity="center_vertical"
android:layout_weight="6"
android:maxLines = "2"
android:lines="2"
android:textSize="#dimen/extra_small_text_size"
android:ellipsize="end"
android:paddingTop = "10dp"
android:paddingBottom = "10dp"
android:text = "Word-of-Mouth Behaviour in Mobile Social Media "/>
<TextView
android:id = "#+id/tv_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:textSize="#dimen/extra_small_text_size"
android:textColor="#color/lightGray"
android:layout_weight = "4"
android:text="11:30 - 12:00"/>
<ImageButton
android:layout_width="#dimen/dimen_image_button_add_remove"
android:layout_height="#dimen/dimen_image_button_add_remove"
android:layout_gravity="center|right"
android:scaleType="fitCenter"
style = "?android:attr/borderlessButtonStyle"
android:src = "#drawable/ic_add_agenda"
/>
</LinearLayout>
And the view class:
package au.com.leremede.acis2016.views;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
import au.com.leremede.acis2016.R;
public class PresentationView extends LinearLayout {
private TextView tvTitle;
private TextView tvTime;
public PresentationView(Context context) {
super(context);
init(context);
}
public PresentationView(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context);
}
private void init(Context context) {
setOrientation(HORIZONTAL);
inflate(context, R.layout.view_presentation, this);
tvTitle = (TextView)findViewById(R.id.tv_title);
tvTime = (TextView)findViewById(R.id.tv_time);
}
public void setTitle(String title)
{
tvTitle.setText(title);
}
public void setTime(String time)
{
tvTime.setText(time);
}
}
I solved this problem myself using the Percent Support Library
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="60dp" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<View
android:id="#+id/empty_view"
android:layout_width="#dimen/session_padding_left"
android:layout_height="#dimen/session_padding_left"
></View>
<ImageButton
android:id="#+id/btn_add_remove_agenda"
android:layout_width="#dimen/dimen_image_button_add_remove"
android:layout_height="#dimen/dimen_image_button_add_remove"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
style="?android:attr/borderlessButtonStyle"
android:src="#drawable/ic_add_agenda"
/>
<android.support.percent.PercentRelativeLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/empty_view"
android:layout_toLeftOf="#id/btn_add_remove_agenda">
<TextView
android:id="#+id/tv_title"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#color/lightGray"
android:layout_alignParentLeft="true"
app:layout_widthPercent="60%"
android:maxLines="2"
android:lines="2"
android:textSize="#dimen/extra_small_text_size"
android:ellipsize="end"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="Word-of-Mouth Behaviour in Mobile Social Media "/>
<TextView
android:id="#+id/tv_time"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="right"
android:layout_alignParentRight="true"
app:layout_widthPercent="40%"
android:textSize="#dimen/extra_small_text_size"
android:textColor="#color/lightGray"
android:text="11:30 - 12:00"/>
</android.support.percent.PercentRelativeLayout>
</RelativeLayout>

I want to draw using canvas over an existing xml background how can I do it?

This is the class where i draw the picture onto this canvas, and on this class I’m trying to set the canvas's background to an existing xml layout that I designed.
The idea of what I want to do is like this made-up function: canvas.setBackground(R.layout.game); on the onDraw method.
The java class:
package com.example.snakesnladders;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
public class MyBringBack extends View {
Bitmap playerW;
public MyBringBack(Context context) {
super(context);
playerW = BitmapFactory
.decodeResource(getResources(), R.drawable.white);
}
#Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawBitmap(playerW, 0, 0, null);
}
}
The XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/easymap"
android:orientation="vertical" >
<TextView
android:id="#+id/whitePlayer"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#drawable/white"
android:visibility="gone" />
<TextView
android:id="#+id/blackPlayer"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="gone"
android:background="#drawable/black" />
<Button
android:id="#+id/btRoll"
android:layout_width="160dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/cubePic"
android:background="#drawable/buttonshape"
android:text="Roll"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/cubePic"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="42dp"
android:layout_marginRight="22dp"
android:background="#drawable/cube" />
<TextView
android:id="#+id/tvTurn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cubePic"
android:layout_alignRight="#+id/btRoll"
android:text="Your turn!"
android:textColor="#color/green"
android:textSize="32dp"
android:textStyle="italic" />
</RelativeLayout>
quick and dirty: Insert the the MyBringBack view in your xml and set height and width to match_parent as last element with a transparent Background
Upüdate your MyBringBack with these constructors:
public MyBringBack (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initView();
}
public MyBringBack (Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}
public MyBringBack (Context context) {
super(context);
initView();
}
private void initView() {
//DO WHAT YOU WANT ON INIT
playerW = BitmapFactory
.decodeResource(getResources(), R.drawable.white);
}
And XML Like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/easymap"
android:orientation="vertical" >
<TextView
android:id="#+id/whitePlayer"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#drawable/white"
android:visibility="gone" />
<TextView
android:id="#+id/blackPlayer"
android:layout_width="32dp"
android:layout_height="32dp"
android:visibility="gone"
android:background="#drawable/black" />
<Button
android:id="#+id/btRoll"
android:layout_width="160dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/cubePic"
android:background="#drawable/buttonshape"
android:text="Roll"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/cubePic"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="42dp"
android:layout_marginRight="22dp"
android:background="#drawable/cube" />
<TextView
android:id="#+id/tvTurn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cubePic"
android:layout_alignRight="#+id/btRoll"
android:text="Your turn!"
android:textColor="#color/green"
android:textSize="32dp"
android:textStyle="italic" />
<your.package.MyBringBack
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/my_bring_back"
android:background="#android:color/transparent" />
</RelativeLayout>

Android custom component works fine at runtime, but doesn't work at design time

I am doing my first steps in Android development.
In the meantime I am trying to create a custom component (for testing purposes) that will later be used on an Activity.
Here's the code for ClearableEditText.java:
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class ClearableEditText extends LinearLayout {
private EditText textField;
private Button button;
public ClearableEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
LayoutInflater.from(this.getContext()).inflate(R.layout.clearable_text, this);
setupViewItems();
}
private void setupViewItems() {
// TODO Auto-generated constructor stub
this.textField = (EditText) findViewById(R.id.editText1);
this.button = (Button) findViewById(R.id.button1);
this.textField.setText("Hello World 123");
}
}
And here's its layout XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
This is the XML layout code for the activity that will integrate the component:
<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"
tools:context=".SegundaActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/ativity2_text" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10" >
<requestFocus />
</EditText>
<com.example.aplicacaoteste.ClearableEditText
android:id="#+id/newComponent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10" >
</com.example.aplicacaoteste.ClearableEditText>
</RelativeLayout>
When I run the app, the component works fine. Nonetheless, as soon as I switch to the Graphical Layout of my Activity, I get the following error message:
java.lang.NullPointerException
Exception details are logged in Window > Show View > Error Log
java.lang.NullPointerException
at com.example.aplicacaoteste.ClearableEditText.setupViewItems(ClearableEditText.java:36)
at com.example.aplicacaoteste.ClearableEditText.onFinishInflate(ClearableEditText.java:26)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:754)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:749)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
I have no clue about what's going on in here. Can anyone help me out?
This source code has working perfectly. This my source code
package com.testapplication.customtools;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class ClearableEditText extends LinearLayout{
private EditText textField;
private Button button;
public ClearableEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
LayoutInflater.from(this.getContext()).inflate(R.layout.clearable_text, this);
setupViewItems();
}
private void setupViewItems() {
// TODO Auto-generated constructor stub
this.textField = (EditText) findViewById(R.id.editText1);
this.button = (Button) findViewById(R.id.button1);
this.textField.setText("Hello World 123");
}
}
This is my Main activity xml Files
<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"
tools:context=".SegundaActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="test" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10" >
<requestFocus />
</EditText>
<com.testapplication.customtools.ClearableEditText
android:id="#+id/newComponent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10" >
</com.testapplication.customtools.ClearableEditText>
</RelativeLayout>
I am not getting any exception. check your package name

Android compound control won't display

I'm trying to create a counter as a compound control.
TallyItem.java
package com.anna.mytallykeeper;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;
public class TallyItem extends LinearLayout {
private Button decrementButton;
private Button incrementButton;
private TextView descriptionText;
private TextView countText;
public TallyItem(Context context) {
super(context);
LayoutInflater inflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflate.inflate(R.layout.tallyitem_layout, this);
/*
String service = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)getContext().getSystemService(service);
li.inflate(R.layout.tallyitem_layout, this, true);
*/
//Get the fields
decrementButton = (Button)findViewById(R.id.decrement);
incrementButton = (Button)findViewById(R.id.increment);
descriptionText = (TextView)findViewById(R.id.description);
countText = (TextView)findViewById(R.id.count);
decrementButton.setOnClickListener(buttonListener);
incrementButton.setOnClickListener(buttonListener);
}
public TallyItem(Context context, AttributeSet attrs) {
super(context, attrs);
}
private OnClickListener buttonListener = new OnClickListener() {
#Override
public void onClick(View v) {
Button button = (Button)v;
int count = Integer.parseInt(countText.getText().toString());
if (button.getText().equals("-")) {
count--;
} else if (button.getText().equals("+")) {
count++;
}
countText.setText("" + count);
}
};
}
tallyitem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/decrement"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:gravity="center"
android:text="-"
android:textSize="30sp"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="200dp"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Item 1"
android:textSize="25sp"
/>
<TextView
android:id="#+id/count"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0"
android:textSize="60sp"
/>
</LinearLayout>
<Button
android:id="#+id/increment"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:gravity="center"
android:text="+"
android:textSize="30sp"
/>
</LinearLayout>
main.xaml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<com.anna.mytallykeeper.TallyItem
android:id="#+id/tallyItem1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</merge>
I am at a loss as to why it won't show up in main.xml.
Thanks for any help.
your view need a constructor with the AttributeSet passed in. Change your constructor to this:
public TallyItem(Context context, AttributeSet attr) {
super(context, attr);
...
}
and get rid of the constructor with the single argument.
try this in your main.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<com.anna.mytallykeeper.TallyItem
android:id="#+id/tallyItem1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</merge>

Rotating ZoomControls

Ok, I've tried extending the ZoomControls class, I've followed the docs, I've read past examples of rotating views, but nothing works. Here's my class:
package imgViewer.Viewer;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.ZoomControls;
class TransformingZoomControls extends ZoomControls {
public TransformingZoomControls(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
#Override
protected void onDraw(Canvas canvas) {
//canvas.save();
canvas.rotate(45,20,20);
super.onDraw(canvas);
//canvas.restore();
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="center_vertical" android:orientation="vertical">
<FrameLayout android:layout_width="match_parent" android:id="#+id/frameLayout1" android:layout_height="fill_parent">
<RelativeLayout android:layout_width="wrap_content" android:id="#+id/imgAccessBtnsContainer" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|bottom">
<ImageButton android:src="#drawable/icon" android:layout_width="wrap_content" android:id="#+id/btnPrevImg" android:layout_height="wrap_content" android:layout_alignParentLeft="true" />
<ImageButton android:src="#drawable/icon" android:layout_width="wrap_content" android:id="#+id/btnNextImg" android:layout_height="wrap_content" android:layout_toRightOf="#id/btnPrevImg" />
</RelativeLayout>
<RelativeLayout android:layout_width="wrap_content" android:id="#+id/rotateBtnsContainer" android:layout_height="wrap_content" android:layout_gravity="left|bottom">
<ImageButton android:src="#drawable/icon" android:layout_width="wrap_content" android:id="#+id/btnRotateLeft" android:layout_height="wrap_content" android:layout_alignParentTop="true" />
<ImageButton android:src="#drawable/icon" android:layout_width="wrap_content" android:id="#+id/btnRotateRight" android:layout_height="wrap_content" android:layout_below="#id/btnRotateLeft" />
</RelativeLayout>
<imgViewer.Viewer.TransformingZoomControls android:id="#+id/zoomControls" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</FrameLayout>
<ImageView android:id="#+id/imagePanel" android:layout_width="fill_parent" android:layout_height="fill_parent">
</ImageView>
</LinearLayout>
As shown in the code block I've even tried not using Save/Restore in the hopes of something actually showing some change but no dice. Is is simply impossible to override this class??

Categories

Resources