我有一个相对布局,我正在以编程方式创建:
RelativeLayout layout = new RelativeLayout( this );
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)
现在我有两个按钮,我想在这个相对布局中添加.但问题是RelatiiveLayout左侧的两个按钮都显示在彼此之间.
buttonContainer.addView(btn1);
buttonContainer.addView(btn2);
Run Code Online (Sandbox Code Playgroud)
现在我想知道如何以编程方式设置按钮的android:layout_alignParentRight="true"或 android:layout_toLeftOf="@id/btn"属性",就像我们在xml中一样?
有没有人知道如何android:layout_span=""在运行时设置/更改Android中的EditText.我已经在我的XML文件中定义了EditText.
<TableRow android:paddingTop="20dip" android:gravity="center_horizontal">
<EditText android:layout_width="150dip"
android:text=""
android:layout_height="40dip"
android:id="@+id/p"
android:layout_span="2">
</EditText>
</TableRow>
Run Code Online (Sandbox Code Playgroud) 我有两个按钮,我想动态加权给予偏好.他们每个人的权重都是.5(这当然会增加LinearLayout的权重为1),但如果偏好是真的,那么我想将他们的权重分别改为.7和.3.我可以用XML设置权重,但我似乎无法找到如何以编程方式更改它.
解
LinearLayout.LayoutParams PO = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, .60f);
LinearLayout.LayoutParams MO = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, .20f);
Run Code Online (Sandbox Code Playgroud) 我对以下问题感到困惑:对于一个问题应用程序,我想为调查显示一个很好的输出,显示可能的答案和回答特定问题的人的百分比.因此,我想在我的应用中添加一个显示百分比的"条形图".我尝试通过使用视图并在线性布局中对它们进行加权来解决此问题.
我想以编程方式添加不同的答案,这是我到目前为止所获得的代码.我的问题是,我没有接近加权观点并调整它们的大小.
/* Add all questions */
RelativeLayout my_root = (RelativeLayout) findViewById(R.id.ownerRL);
/* Add a new Linearlayout as a container for the question */
LinearLayout A = new LinearLayout(this);
A.setOrientation(LinearLayout.HORIZONTAL);
my_root.addView(A);
/* Create a new View in this container, for the status bar */
View new_view = new View(getBaseContext());
new_view.setBackgroundColor(Color.YELLOW);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(50, 20, 3);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) A.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.question1);
A.addView(new_view);
View new_view2 = new View(getBaseContext());
new_view.setBackgroundColor(Color.GREEN);
ViewGroup.LayoutParams lp2 = new ViewGroup.LayoutParams(50, 20);
RelativeLayout.LayoutParams params2 = …Run Code Online (Sandbox Code Playgroud) 想象一个Android应用程序,其中3个TextView采用线性布局,一个顺序位于另一个之下,然后是2个按钮.1按钮需要隐藏第二个文本视图,第二个按钮需要再次显示它.
唯一的要求是当第二个文本视图消失时,它不应占用任何空间,这意味着第三个文本视图应该在它消失时占据其空间.
我尝试使用INVISIBLE和VISIBLE设置,但是,空白占位符仍保留在第二个文本视图的位置.
我尝试使用GONE,它消除了空白区域,但是我无法再次显示第二个文本视图.
你知道实现这个目标的方法吗?
例:
////////////////////////////
initial state:
textview1
textview2
textview3
button1
button2
--> user pushes button1
new state:
textview1
textview3
button1
button2
--> user pushes button2
new state: initial state
////////////////////////////
Run Code Online (Sandbox Code Playgroud)
谢谢