我正在尝试制作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背景,并希望保留当前的外观.
有多种方法可以创建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) 我有一个有问题模型的应用程序,当我去创建一个记录时,提交按钮什么都不做.除非我刷新页面并尝试再次添加它,否则没有错误只是根本不执行.当我去更新记录时也会发生同样的情况.
这是我的控制器
class ProblemsController < ApplicationController
include Concerns::Votes
def index
@problems = Problem.all
end
def show
@problem = find_problem
end
def new
@problem = Problem.new
end
def edit
@problem = find_problem
end
def create
@problem = current_user.problems.new(problem_params)
@problem.save
redirect_to @problem
end
def update
@problem = find_problem
if @problem.update_attributes(problem_params)
redirect_to @problem
else
redirect_to @problem
end
end
private
def find_problem
@problem = Problem.find(params[:id])
end
def problem_params
params.require(:problem).permit(:name, :description, :url)
end
end
Run Code Online (Sandbox Code Playgroud)
这是我在new.html上渲染的_form.html.erb部分
<div class="row">
<div class="large-12 columns">
<%= form_for @problem do |f| …Run Code Online (Sandbox Code Playgroud) 在Material Design指南中,Google推出了一种新的按钮样式,即FAB Button.我找到了如何制作它的说明,但是添加阴影时遇到了麻烦.怎么能实现这一目标?
android button shadow floating-action-button android-5.0-lollipop
我在我的网站页面上使用引导按钮,我想更改禁用按钮的颜色.一个"灰显"的按钮,您无法单击.有没有办法可以使用CSS改变颜色?任何课程?
非常感谢你!
https://github.com/h6ah4i/android-advancedrecyclerview
就它提供的功能而言,这似乎是一个很棒的库.但是,它缺乏良好的文档.它有一个关于Swipeable项目的"教程" ,但像其他人一样,我无法遵循它.
有没有人有一个工作的例子,或者任何人都可以使用这个库制作一个简单的用例来刷一个项目并在其下面显示一个按钮?对于许多对此功能感兴趣的人来说,它会很有用.