我正在扩展LinearLayout类,但方向存在一些问题。 我正在添加此视图,我正在创建其他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);
}
}
我试图在模拟器和我的asus平板电脑中看到它。 有任何想法吗?谢谢!
答案 0 :(得分:2)
在扩展LinearyLayout setOrientation(LinearLayout.VERTICAL);