简而言之,是否有可能告诉a中的孩子RelativeLayout
始终匹配其高度,而RelativeLayout
不管其他孩子的RelativeLayout
行为如何?简而言之,就是这样.详情如下.
我想要实现的是一个ListView
至少有三个视图的行,其中一个视图在列表条目的右侧是一种条带(下面的红色视图).我遇到的问题是TextView
左侧有一个,并且根据我有多少文本,条纹不会填满整个布局.下面的图片非常清楚地解释了这一点.
ListView
项目布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="@+id/bottom_line"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="#fc0" />
<!-- Why match_parent does not work in view below? -->
<View
android:id="@+id/stripe"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="#f00" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/stripe"
android:text="This is a very long line, meant to completely break the match_parent property of the box at right"
style="?android:textAppearanceLarge"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
结果:
match_parent
没有区别.我做的.重复这个问题,我希望红色条纹始终垂直填充父级.您可以看到条带未对齐到根的顶部.
注意:上面的例子是我能想到的最简单,最独立的例子.它只是一个由静态数组填充ListActivity …
我希望能够在禁用的交换机上响应点击事件,这可能吗?
我有一个开关,直到用户填写一些信息才启用,所以它看起来像这样:
我想提示用户填写信息,如果他们点击禁用的开关并带有对话框,如下所示:
mySwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!userInfo.isFilled){
new AlertDialog.Builder(MainActivity.this)
.setTitle("Fill out info first!")
.setMessage("You must first fill out info before turning on this featurel")
.setNeutralButton("Okay", null)
.show();
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是,onClick()
单击禁用的开关时不会触发,所以当用户点击它时如何获得?