在我的Android应用程序中,drawable文件夹中有许多图像.在我的布局中有两个按钮:后退和下一步按钮.在单击下一个和后退按钮时,2个不同的图像被加载到相同的布局上(所有图像都是通用的).
问题:我能够在下一个/后退按钮的点击上加载图像,但是在到达最后一个图像后,我想使我的下一个按钮禁用,并且后退按钮也是如此.当用户在第一张图像上时,应该禁用后退按钮.代码如下:
public class SequencerActivity extends Activity implements OnClickListener
{
private int imageCounter = 0;
private ImageView imageLoader;
private int[] imageList = {R.drawable.image_wo_lbl_0, R.drawable.image_wo_lbl_1, R.drawable.image_wo_lbl_2, R.drawable.image_wo_lbl_3, R.drawable.image_wo_lbl_4, R.drawable.image_wo_lbl_5,
R.drawable.image_wo_lbl_6, R.drawable.image_wo_lbl_8, R.drawable.image_wo_lbl_9,R.drawable.image_wo_lbl_10, R.drawable.image_wo_lbl_11};
@Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.parent_frame);//this one is the common parent layout for all image views
super.onCreate(savedInstanceState);
/*requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
//int image1 = R.drawable.image_w_lbl_0;
imageLoader = (ImageView) findViewById(R.id.imageLoader);
//imageLoader.setImageResource(image1);
ImageButton next = (ImageButton) findViewById(R.id.next);
ImageButton back = (ImageButton) findViewById(R.id.back);
next.setOnClickListener(this);
back.setOnClickListener(this);
//show the default image
this.loadImage(imageList[imageCounter]); …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作4个按钮,在Android上的纵向视图中均匀分布.
空间应根据屏幕尺寸向上和向下缩放,每个按钮和边框之间的空间均匀.
我尝试使用线性布局,重量和布局重力,但似乎我不能垂直居中按钮.
这是Android布局的错误吗?更可能只是我.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_f"
>
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_b"
>
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_a"
>
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center"
>
<Button
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
>
</Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我知道这是一个以前曾多次被问过的问题,但我似乎无法在我的代码中解决它.我有两个按钮,当按下一个按钮时,我希望将其保持在选定状态,反之亦然.我尝试过使用setSelected和setPressed,但我似乎无法让它工作.这是我正在使用的代码:
region_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
objects = category;
adap.notifyDataSetChanged();
proximity_button.setPressed(false);
region_button.setPressed(true);
}
});
proximity_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
objects = proximity;
adap.notifyDataSetChanged();
region_button.setPressed(false);
proximity_button.setPressed(true);
}
});
Run Code Online (Sandbox Code Playgroud)
编辑: 根据评论,我需要添加我有按钮的自定义xml背景,并希望保留当前的外观.
我想通过按下按钮在ImageView中打开一个图像.我需要图像可缩放和可滚动.我怎样才能最好地完成这个?谢谢!
图像可以是PNG或JPG
非常感谢!
这是我的新代码,你不介意浏览并给我一个TAG,ZOOM等所有问题的解决方案...我也知道我需要添加我的图像res到它
package com.DS;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class CheatMathActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button1 = (Button) findViewById(R.id.button1);
button1.setOnTouchListener(new View.OnTouchListener(){
public void onTouch(View v) {
//Opens Algebra Image
public …Run Code Online (Sandbox Code Playgroud) 有多种方法可以创建HTML按钮以导航到其他页面.
方法1
<button id="btn_click">Click Me</button>
<script>
$('#btn_click').on('click', function() { window.location = 'http://www.google.com'; });
</script>
Run Code Online (Sandbox Code Playgroud)
方法2
<button onclick="window.location='http://www.google.com'">Click Me</button>
Run Code Online (Sandbox Code Playgroud)
方法3
<a class="click-me" href="http://www.google.com">Click me</a>
<style>
.clickMe {
-moz-appearance: button;
-ms-appearance: button;
-o-appearance: button;
-webkit-appearance: button;
appearance: button;
text-decoration: none;
color: #000;
padding: 0.2em 0.4em;
}?
</style>
Run Code Online (Sandbox Code Playgroud)
appearance是一个CSS3属性)方法4
<form action="http://www.google.com">
<button>Click Me</button>
</form>
Run Code Online (Sandbox Code Playgroud)
<form>标签.如果有另一个提交按钮,则不起作用程序员,哪种方法是最有效的(因此广泛使用),为什么?
注意:我们可以将其作为社区维基吗?
在下面的代码中,我有一个TextField和一个Button.我需要在TextField为空时禁用Button,以便我可以避免向数据库输入空值.如何禁用该按钮?
private VBox addVBox() {
VBox vb1 = new VBox();
vb1.setPadding(new Insets(15, 20, 25, 20));
vb1.setSpacing(15);
vb1.setStyle("-fx-background-color: #333333;");
final Label label = new Label("Staff Details");
label.setFont(Font.font("Arial", FontWeight.BOLD, 20));
label.setTextFill(Color.WHITE);
TableColumn sub = new TableColumn("Staff Name");
sub.setMinWidth(400);
sub.setCellValueFactory(
new PropertyValueFactory<Staff, String>("subName"));
table.setItems(data);
table.getColumns().addAll(sub);
addSubName = new TextField();
addSubName.setPromptText("Staff Name");
addSubName.setPrefSize(200, 30);
final Button b2 = new Button("Add");
b2.setFont(Font.font("Calibri", FontWeight.BOLD, 17));
b2.setPrefSize(70, 30);
b2.setStyle(" -fx-base: #0066ff;");
b2.setTextFill(Color.BLACK);
b2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
msg = addSubName.getText();
try {
enterStaff(); …Run Code Online (Sandbox Code Playgroud) 我一直试图追踪这个问题一段时间了.我想我前段时间确实找到了解释.不幸的是,它丢失了代码注释.
我正在尝试Material Borderless-Button用Java 创建一个.首先,这是按钮在框架中的样子:
按钮bg(button_borderless_material.xml):
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:id="@id/mask"
android:drawable="@drawable/btn_default_mtrl_shape" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
在drawable被用作掩模(btn_default_mtrl_shape.xml):
<?xml version="1.0" encoding="utf-8"?>
<!-- Used as the canonical button shape. -->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/button_inset_horizontal_material"
android:insetTop="@dimen/button_inset_vertical_material"
android:insetRight="@dimen/button_inset_horizontal_material"
android:insetBottom="@dimen/button_inset_vertical_material">
<shape android:shape="rectangle"
android:tint="?attr/colorButtonNormal">
<corners android:radius="@dimen/control_corner_material" />
<solid android:color="@color/white" />
<padding android:left="@dimen/button_padding_horizontal_material"
android:top="@dimen/button_padding_vertical_material"
android:right="@dimen/button_padding_horizontal_material"
android:bottom="@dimen/button_padding_vertical_material" />
</shape>
</inset>
Run Code Online (Sandbox Code Playgroud)
Java等价于inset-drawable(btn_default_mtrl_shape.xml):
Drawable createButtonShape(Context context, int color) {
Resource res = context.getResources();
int radius = res
.getDimensionPixelSize(R.dimen.control_corner_material);
int …Run Code Online (Sandbox Code Playgroud) https://github.com/h6ah4i/android-advancedrecyclerview
就它提供的功能而言,这似乎是一个很棒的库.但是,它缺乏良好的文档.它有一个关于Swipeable项目的"教程" ,但像其他人一样,我无法遵循它.
有没有人有一个工作的例子,或者任何人都可以使用这个库制作一个简单的用例来刷一个项目并在其下面显示一个按钮?对于许多对此功能感兴趣的人来说,它会很有用.
这是因为尽量保持我的html语义正确而导致的问题.
我有一个父按钮,它在同一页面中同时执行一个功能,并作为嵌套锚点的大容器的父标记 - 重定向到另一个页面 - 以及作为另一个按钮的父标记的div标记这是假设执行某些操作.
<button>
<div id="the-most-big-container"
<a href="http://www.RedirectMeToAnotherPage.com"></a>
<div>
<button> do some action </button>
</div>
</div>
</button>
Run Code Online (Sandbox Code Playgroud)
我尝试嵌套按钮,给它一个类和id,没有我应用于类的属性和id在子按钮上执行,更多此外,子按钮完全脱离大容器并放置在DOM就像它是一个完整的独立标签,没有任何其他标签嵌套.
[更新]
显然这是禁止将按钮嵌套在另一个按钮内,但是我想要解释为什么嵌套按钮的行为不响应css样式,以及它现在如何正确地关于DOM,它现在是一个完全独立的标签本身或什么?
此外,现在我将被迫将父按钮标记更改为任何其他标记,以便我可以在其中嵌套子按钮.我想建议父代按钮标签的替代标签ex:我可以将父按钮更改为div标签,
但是我需要一个语义上更具描述性的标签(除了div之外的其他东西),我首先将该父按钮用作切换按钮,这样当我点击它时它会显示并隐藏最大的 - 容器DIV.