我可能遗漏了一些东西,但我找不到将子视图添加到具有特定布局参数的指定索引处的视图的方法。有addView(View v, LayoutParams lp)和有addView(View v, int index)- 但我找不到指定两者的方法。
我错过了什么?
我知道它和这里的问题相同
但是它还没有得到答案,所以我在这里试试,因为我也需要它:)
我得到了一个数组:(我缩短了SO的数组/代码)
ScrollView sv = new ScrollView(this);
TableLayout ll=new TableLayout(this);
HorizontalScrollView hsv = new HorizontalScrollView(this);
TableRow tbrow=new TableRow(this);
for(int i=0;i<mConnector.idArray.size();i++) {
tbrow=new TableRow(this);
tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
tbrow.setBackgroundColor(Color.rgb(51, 51, 51));
ll.addView(tbrow);
}
hsv.addView(ll);
sv.addView(hsv);
setContentView(sv);
Run Code Online (Sandbox Code Playgroud)
遗漏了数组中的信息,我认为你不需要它.
但是如何在每一行中添加边框(更喜欢水平和垂直)?我希望这是解决方案:
tbrow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
tbrow.setBackgroundColor(Color.rgb(51, 51, 51));
Run Code Online (Sandbox Code Playgroud)
但它只是将整张桌子的颜色变为灰色.
希望我足够清楚,并希望他们是一个解决方案.
我有一个捕获用户签名的自定义视图(John Hancock).我希望我们的应用程序尽可能地易于访问,因此我需要特别注意确保优化我们的TalkBack屏幕和触摸式触摸屏.由于触摸式触摸将所有一个手指手势更改为两个手指手势,因此它会破坏自定义签名视图.
我想要做的是通过触摸式探索在悬停时宣布视图的内容描述,然后在用户双击时启用视图.这将允许他们使用像普通用户这样的单个指针在视图顶部绘制.
我一直在搜索,但很难找到有关Android辅助功能库的详细文档.有任何想法吗?
我想将RadioButton的可见性设置为INVISIBLE或GONE.由于某种原因,这是行不通的.
RadioButton myRadioButton = (RadioButton) findViewById(R.id.my_radio_button_id);
myRadioButton.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
要么
myRadioButton.setVisibility(View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)
没有错误返回,它只是没有做任何事情.
不过我在RadioGroup上尝试了这个
RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_quiz_answers);
myRadioGroup.setVisibility(View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)
它可以很好地隐藏整个组.有没有办法隐藏其中一个RadioButtons?我有一组3个问题的答案,但在某些情况下我想隐藏最后一个问题.
I have a view that I'm removing with removeView(), and then a view that is replacing it with an addView(). Both of these views are within a FrameLayout. I would like to be able to do a Shared Element Transition between two shared images in these layouts, but don't really know how to go about doing that as the android tools seems to be built with the (perhaps reasonable) idea that you will only have shared element transitions between activities …
android android-animation android-layout android-view android-transitions
我试图在按下按钮时更改 ConstraintLayout 中视图的左约束(指南)。我的布局 XML(相关部分)如下所示:
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:indeterminate="true"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/guideline_bcrumbs_bottom"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline_group_left"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<android.support.constraint.Guideline
android:id="@+id/guideline_group_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.2"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="205dp"/>
<android.support.constraint.Guideline
android:id="@+id/guideline_category_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.45"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="461dp"/>
Run Code Online (Sandbox Code Playgroud)
在这里,我要进度条的修改constraintLeft_toLeftOf财产guideline_group_left到guideline_category_left动态。有没有办法实现这一目标?
编辑:
我添加了以下几行来调整约束(基于此链接:http : //www.techotopia.com/index.php/Managing_Constraints_using_ConstraintSet)
ConstraintSet set = new ConstraintSet();
set.connect(mProgressBar.getId(), ConstraintSet.LEFT, R.id.guideline_category_left, ConstraintSet.LEFT, 0);
set.connect(mProgressBar.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, 0);
set.applyTo(mConstraintLayout);
Run Code Online (Sandbox Code Playgroud)
但是,在这些更改之后,进度条根本不显示。我觉得我很接近,但可能错过了一些东西。
编辑 2
我意识到我忘记添加以下行,这就是它不起作用的原因。
set.clone(mConstraintLayout);
Run Code Online (Sandbox Code Playgroud) 我想向父视图添加一个宽度为 100% 和 X%(例如:让它成为 40%)的视图
我有这个:
private RelativeLayout getParentView(){
return (RelativeLayout) MyActivity.this.getWindow().getDecorView().getRootView();
}
Run Code Online (Sandbox Code Playgroud)
我应该将父视图转换为 LinearLayout 或 RelativeLayout 可以实现吗?
以及如何以编程方式以百分比设置“myView”宽度和高度?
谢谢
java user-interface android android-view android-relativelayout
我有一个RelativeLayout我已经设置了背景的drawable. 我能够RelativeLayout在RadioButton检查时将背景更改为另一个背景。但是当它改变时我如何给它一个动画?
代码:activity_main.xml:
<RelativeLayout
android:layout_width="80dp"
android:layout_height="50dp"
android:gravity="center"
android:background="@drawable/original"
android:id="@+id/rel1">
<RadioButton
android:id="@+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
原始.xml(可绘制):
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#ffffff">
</solid>
<corners
android:radius="50dp">
</corners>
</shape>
Run Code Online (Sandbox Code Playgroud)
按下.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#2196F3">
</solid>
<corners
android:radius="50dp">
</corners>
</shape>
Run Code Online (Sandbox Code Playgroud)
Java类:
radio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
relativeLayout.setBackgroundResource(R.drawable.pressed);
}
}
});
Run Code Online (Sandbox Code Playgroud) animation android android-animation android-layout android-view
我将菜单抽屉用作清单,并且 onDrawerClosed 根据 int 值将向用户收费或不保存更改。但是 onDrawerClosed 方法调用了两次,一次使用 int 和正确的值,一次使用 int 和值 0?这导致我的程序同时调用 if 和 else 语句,以便保存更改并提示他们付款。
//Used so that when drawer closed banned list saves
public void drawerListener(){
mDrawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
customAdaptor.clearJustChanged();
}
@Override
public void onDrawerClosed(View drawerView) {
System.out.println("Cost of Changes:" + customAdaptor.getUserCostOfChange());
if (customAdaptor.getUserCostOfChange() > 0) {
getBuyAlert(customAdaptor.getUserCostOfChange());
customAdaptor.setUserCostOfChange(0);
}
else {
bannedList = customAdaptor.getBannedList();
databaseReference.child("BannedApps").setValue(bannedList);
}
}
@Override
public void onDrawerStateChanged(int newState) …Run Code Online (Sandbox Code Playgroud) LayoutInflaterAndroid中到底是什么?使用它的目的方法是什么?我可以找到不同类型的用法,但在我的情况下无法找到哪一个套件.
关于这个问题
关于正确使用该inflate()方法,我有很多困惑.在互联网上进行研究时,大多数结果都是错误的或不完整的.即使是官方文件也很模糊.这篇文章是我在不同地方可以找到的内容的总结.我相信这对像我这样的初学者会有所帮助
android ×10
android-view ×10
java ×2
animation ×1
drawerlayout ×1
layoutparams ×1
listener ×1
tablerow ×1
talkback ×1