0
我正嘗試使用按鈕創建類似圖形的結構。
我想基於seek bar的值動態修改這些按鈕的高度。向上方向動態修改按鈕高度
我能夠實現這個如本屏幕截圖1.但問題是按鈕生長在向下方向上的高度(這是他們的默認行爲)。
如何讓按鈕向上生長如下圖所示?
的Xml
<Button
android:id="@+id/btnGraph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/seekBar"
android:background="#99f"/>
<Button
android:id="@+id/btnGraph2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/seekBar"
android:layout_toRightOf="@id/btnGraph"
android:background="#9f9"/>
活動
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromTouch) {
tvValue.setText("Value = " + progress);
// NEGATIVE HEIGHT WONT WORK HERE...
lp = new RelativeLayout.LayoutParams(new ViewGroup.MarginLayoutParams(
50, progress * 10));
lp.setMargins(10, 300, 0, 0);
btnGraph.setLayoutParams(lp);
lp = new RelativeLayout.LayoutParams(new ViewGroup.MarginLayoutParams(
50, progress * 5));
lp.setMargins(100, 300, 0, 0);
btnGraph2.setLayoutParams(lp);
}
我做什麼傻?任何幫助讚賞。
什麼是按鈕的父視圖,如果它的線性佈局可以將重力設置爲底部。 – Gan
相對佈局 – GAMA
我試過'btnGraph.setGravity(Gravity.BOTTOM);',但它沒有任何影響... – GAMA