I want to set the opacity of background of LinearLayout
, I found this solution that works fine if I use normal layouts, but in the case of android-widgets
we have to set layout different I wrote the following code
public class AlphaLayout extends LinearLayout {
public AlphaLayout (Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public AlphaLayout (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onAnimationStart() {
AlphaAnimation alphax = new AlphaAnimation(0.5F, 0.5F);
alphax.setDuration(0);
alphax.setFillAfter(true);
this.startAnimation(alphax);
super.onAnimationStart();
}
}
And my corresponding widget xml layout is
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin" >
<com.exercise.HelloWidget.AlphaLayout
android:id="@+id/myWidgetLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/appwidget_dark_bg"
android:orientation="horizontal" >
<TextView
android:id="@+id/song_info"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="Hello"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white" />
<TextView
android:id="@+id/timeWidget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="03:30"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white" />
</com.exercise.HelloWidget.AlphaLayout>
after running the project When I add a widget to my homescreen, its displaying an error Problem loading widget
Can you tell me what I am doing wrong ? Your help will be appreciated.