在某些应用程序中有以下内容,关注者和帖子,它们是android ofcourse中的图像按钮还是使用onclick方法的布局?
因为你看到"后面的"保持不变但数量变化。我们是否使用了图像按钮并将textview置于其上方?考虑到我是否尝试用不同的语言提供它,我想到了这一点。
答案 0 :(得分:0)
您可以制作自己的自定义视图并扩展按钮
并向其添加多个视图,然后处理每个视图的点击
请解释更多你的问题...
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.mhp.customimagebtn"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!--other tags here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/following"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:orientation="vertical"
android:background="@drawable/bg"
android:onClick="followingClick" >
<TextView
android:id="@+id/following_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_margin="5dp"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Following"
android:textColor="#eee"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/follower"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:orientation="vertical"
android:background="@drawable/bg"
android:onClick="followerClick" >
<TextView
android:id="@+id/follower_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_margin="5dp"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Following"
android:textColor="#eee"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
<!--other tags here-->
</LinearLayout>
bg.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" >
<item android:state_pressed="true">
<shape>
<gradient
android:startColor="#f00"
android:endColor="#f00"
android:angle="270"/>
<stroke
android:width="2dp"
android:color="#eee"/>
<corners
android:radius="3dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ccc"
android:endColor="#ccc"
android:angle="270"/>
<stroke
android:width="2dp"
android:color="#ccc"/>
<corners
android:radius="3dp" />
</shape>
</item>
</selector>
main.class
public class Main extends Activity {
TextView followingNumber,followerNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
followingNumber = (TextView) findViewById(R.id.following_number);
followerNumber = (TextView) findViewById(R.id.follower_number);
}
public void setFollowingNumberText(String number){
followingNumber.setText(number);//you can update number of following here
}
public void setFollowerNumberText(String number){
followerNumber.setText(number);//you can update number of follower here
}
public void followingClick(View view){
//do something
}
public void followerClick(View view){
//do somthing
}
}