开发者

creating buttons for dashboard, problems with onClick, maybe better solution?

开发者 https://www.devze.com 2023-03-27 17:39 出处:网络
I am currently implementing my dashboard. My current solution for buttons is this: <LinearLayout android:layout_width=\"fill_parent\"

I am currently implementing my dashboard. My current solution for buttons is this:

<LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_weight="33"
                        android:gravity="center_horizontal"
       开发者_开发知识库                 android:orientation="vertical"
                        android:background="@drawable/button_frame"
                        android:id="@+id/viewAddItemBtn"
                        android:onClick="BtnListener"
                        >
                    <ImageButton
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:background="@drawable/addbutton"

                        />
                    <TextView 
                        android:text="Add Item"
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="5dp"
                        />
                        </LinearLayout>

However, I now have some problems with 1. the "clickability" and the states (focused/pressed/normal). As you might guess out of my code: If i click on the "ImageButton" (which could basically be a imageview too on solution) it does nothing. (because onClick is not assigned, I thought it would inherit the attribute from its overall LinearLayout). Second thing is, if I make the "ImageButton" Clickable too, i guess the states won't be called, am I right here?

is there any better solutions for my design? little demo-picture on how the button should look like: http://i.imgur.com/aI2Vb.png


Why do not you add the onClick property for all of the components:

<LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_weight="33"
                        android:gravity="center_horizontal"
                        android:orientation="vertical"
                        android:background="@drawable/button_frame"
                        android:id="@+id/viewAddItemBtn"
                        android:onClick="BtnListener"
                        >
                    <ImageButton
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:background="@drawable/addbutton"
                        android:onClick="BtnListener"

                        />
                    <TextView 
                        android:text="Add Item"
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="5dp"
                        android:onClick="BtnListener"
                        />
                        </LinearLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消