【发布时间】:2015-01-21 18:55:23
【问题描述】:
要求:我想设计一个嵌入图像的圆形按钮,如果我单击一次按钮,则图像将更改为另一个图像,并且它应该导航到另一个屏幕。我怎样才能使它成为可能。
在这里我可以做圆形按钮,当点击图像时,它会变成另一个图像。但我的问题是:图像以方形模式显示,但不是圆形按钮。它显示在按钮的边界之外。我需要以圆形方式显示图像,它应该在圆形按钮中。我怎样才能使它成为可能: 这是我的代码:
MainActivity.java:
package com.example.circularbutton;
import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CircleImageView b1=(CircleImageView) findViewById(R.id.btn);//showing issue here
b1.setImageResource(R.drawable.my);
final Context context=this;
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Hello.class);
startActivity(intent);
}
} );
}
}
my *myborder3.xml* it shapes the button
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="5dp"
android:color="#000000"
/>
<padding android:left="45dp"
android:top="45dp"
android:right="45dp"
android:bottom="45dp"
/>
<corners android:bottomRightRadius="55dip" android:bottomLeftRadius="55dip"
android:topLeftRadius="55dip" android:topRightRadius="55dip"/>
</shape>
*my.xml* is:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/mine">
</item>
<item android:state_pressed="true" android:drawable="@drawable/mine1"></item>
<item android:drawable="@drawable/mine10" ></item>
</selector>
activiyt_main.xml:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.circularbutton.MainActivity" >
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/myborder3"
android:text="Test" />
</RelativeLayout>
build.gradile:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile de.hdodenhof.circleimageview.CircleImageView //added here
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'CircularBUtton'
gdxVersion = '1.5.3'
roboVMVersion = '1.0.0-beta-03'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.1'
aiVersion = '1.4.0'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d- platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d- platform:$gdxVersion:natives-x86"
}
}
project(":html") {
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
我是 android 开发的初学者。请帮帮我。
更清楚:
按钮和图像应该是圆形的,当用户点击它时,它应该在圆形的同一个按钮中显示另一个图像,并且应该导航到另一个屏幕
【问题讨论】:
-
你可以添加一些输出的截图吗?
-
您在任何地方都没有按钮点击监听器 - 应用程序如何知道点击按钮时该做什么?
-
如果我点击按钮,它会变成另一个图像。对不起,我提供了我将进一步提供的听众。但是我怎样才能将图像塑造成圆形(它应该适合圆形按钮)。如果我单击屏幕截图中显示的图像(my.xml 中的 mine10),它会显示另一张图像(my.xml 中的 mine1)1-2 秒,然后再次仅显示第一张图像。
-
你也可以发布你的按钮 onclicklistener 代码吗?
-
我认为这对我的要求没有必要。好的,无论如何我都会用监听器更新代码。
标签: android