我正在扩展 LinearLayout 类,但方向存在一些问题。我正在将我正在创建的这个视图添加到其他线性布局中,但它仍然设置为水平。这是代码:
package com.simplemathgame;
import java.util.Date;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TableLayout;
public class GraphBar extends LinearLayout {
private Date date;
private int totalDrills;
private int rightDrills;
private int score;
private int height;
private final int widht = 30;
private final int totHeight = 300;
LinearLayout.LayoutParams barParams;
public GraphBar(Context context, int totalDrills, int rightDrills, Date date) {
super(context);
this.date = date;
this.rightDrills = rightDrills;
this.totalDrills = totalDrills;
this.setScore();
setParams();
this.barParams = new LinearLayout.LayoutParams(0,this.widht);
}
private void setScore(){
this.height = (this.rightDrills / this.totalDrills) * totHeight;
}
private void setParams(){
this.barParams = new LinearLayout.LayoutParams(this.height,this.widht);
this.barParams.setMargins(5, 0, 0, 0);
this.setBackgroundColor(Color.CYAN);
this.setOrientation(LinearLayout.VERTICAL);
this.setGravity(Gravity.BOTTOM);
this.setLayoutParams(this.barParams);
}
}
我试图在模拟器和我的华硕平板电脑中看到它。有任何想法吗?谢谢!