我的行中有3个文本小部件。
中间文本条目可以跨越多行,但前两个会非常小。
我想让第一个小部件的文本位于行的顶部,第三个小部件的文本位于行的底部。
它基本上与此图像类似
所以基本上第一个小部件是开头报价,然后是第3个结束报价。
我可以在行上设置一个crossAxisAlignment来开始或结束,这将移动引号,但它会移动它们。
目前,我有这样的事情:
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Text('"'),
),
Expanded(
child: Text(
entry.text,
style: style,
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
color: Colors.yellow,
child: Text(
'”',
textAlign: TextAlign.start,
),
),
],
);
但我不确定如何将底部引号与文本底部对齐,此时它位于顶部。
答案 0 :(得分:3)
IntrinsicHeight是您正在寻找的小部件。它可以正常使用该小部件。
@override
Widget build(BuildContext context) {
return Scaffold(
body: new IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.topLeft,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Text('"'),
),
),
Expanded(
child: Text(
"The middle text entry can span several lines, but the first two will be really small. I'm wanting to have the first widget have the text at the top of the row and the 3rd widget to have the text at the bottom of the row. It's basically something similar to this image"
),
),
new Align(
alignment: Alignment.bottomRight,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Text(
'”',
textAlign: TextAlign.start,
),
),
),
],
),
));
}
答案 1 :(得分:1)
一个想法是创建一个堆栈,而不是用public class MainActivity extends Activity {
EditText fname,lname,classid,classname,pointgrade,lettergrade,studentid;
Button add,view,viewall,delete,modifystudent, modifyclass, modifygrade;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
studentid=(EditText)findViewById(R.id.studentID);
fname=(EditText)findViewById(R.id.firstName);
lname=(EditText)findViewById(R.id.lastName);
classid=(EditText)findViewById(R.id.classID);
classname=(EditText)findViewById(R.id.className);
pointgrade=(EditText)findViewById(R.id.gradePoint);
lettergrade=(EditText)findViewById(R.id.letterGrade);
add=(Button)findViewById(R.id.addbtn);
viewall=(Button)findViewById(R.id.viewall);
delete=(Button)findViewById(R.id.deletebtn);
modifystudent=(Button)findViewById(R.id.modifystudent);
modifyclass=(Button)findViewById(R.id.modifyclass);
modifygrade=(Button)findViewById(R.id.modifygrade);
db=openOrCreateDatabase("STUDENTGRADES", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS CUSTOMER_TABLE(studentid VARCHAR, fname VARCHAR, lname VARCHAR, classid VARCHAR, classname VARCHAR, pointgrade INTEGER, lettergrade VARCHAR);");
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(fname.getText().toString().trim().length()==0||
lname.getText().toString().trim().length()==0 || studentid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter First & Last Name and Student ID");
return;
}
db.execSQL("INSERT INTO CUSTOMER_TABLE VALUES('"+studentid.getText()+"','"+fname.getText()+"','"+lname.getText()+"','"+classid.getText()+"','"+classname.getText()+
"','"+pointgrade.getText()+"','"+lettergrade.getText()+"');");
showMessage("Success", "Record added successfully");
clearText();
}
});
delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(studentid.getText().toString().trim().length()==0 || classid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Student and Class ID ");
return;
}
Cursor c=db.rawQuery("SELECT * FROM CUSTOMER_TABLE WHERE studentid='"+studentid.getText()+"' AND classid='"+classid.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM CUSTOMER_TABLE WHERE studentid='"+studentid.getText()+"' AND classid='"+classid.getText()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid First and Last Name or Student ID");
}
clearText();
}
});
modifystudent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(fname.getText().toString().trim().length()==0 || lname.getText().toString().trim().length()==0 || studentid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Student First & Last Name and ID to update student info. \n\nAll other Field Entries will be ignored");
return;
}
Cursor c=db.rawQuery("SELECT * FROM CUSTOMER_TABLE WHERE studentid='"+studentid.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE CUSTOMER_TABLE SET fname='"+fname.getText()+"',lname='"+lname.getText()+"' WHERE studentid='"+studentid.getText()+"'");
showMessage("Success", "Name Record Modified");
}
else
{
showMessage("Error", "Invalid First and Last name or Student ID");
}
clearText();
}
});
modifyclass.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(studentid.getText().toString().trim().length()==0 || classid.getText().toString().trim().length()==0 || classname.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Student & Class ID to update class. \n\nAll other Field Entries will be ignored");
return;
}
Cursor c=db.rawQuery("SELECT * FROM CUSTOMER_TABLE WHERE classid='"+classid.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE CUSTOMER_TABLE SET classid='"+classid.getText()+"',classname='"+classname.getText()+"' WHERE studentid='"+studentid.getText()+"' AND classid='"+classid.getText()+"'");
showMessage("Success", "Class Record Modified");
}
else
{
showMessage("Error", "Invalid First and Last name or Class ID");
}
clearText();
}
});
modifygrade.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(studentid.getText().toString().trim().length()==0 || classid.getText().toString().trim().length()==0 || classname.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Student & Class ID to update grades. \n\nAll other Field Entries will be ignored");
return;
}
Cursor c=db.rawQuery("SELECT * FROM CUSTOMER_TABLE WHERE classid='"+classid.getText()+"' AND studentid='"+studentid.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE CUSTOMER_TABLE SET pointgrade='"+pointgrade.getText()+"',lettergrade='"+lettergrade.getText()+"' WHERE classid='"+classid.getText()+"' AND studentid='"+studentid.getText()+"'");
showMessage("Success", "Grade Record Modified");
}
else
{
showMessage("Error", "Invalid First and Last name or Class ID");
}
clearText();
}
});
viewall.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Cursor c=db.rawQuery("SELECT * FROM CUSTOMER_TABLE", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("ID: "+c.getString(0)+"\n");
buffer.append("Student Name: "+c.getString(1)+" " +c.getString(2)+"\n");
buffer.append("Class ID: "+c.getString(3)+"\n");
buffer.append("Class Name: "+c.getString(4)+"\n");
buffer.append("Points: "+c.getString(5)+"\n");
buffer.append("Grade: "+c.getString(6)+"\n\n");
}
showMessage("Student Report", buffer.toString());
}
});
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
public void clearText()
{
studentid.setText("");
fname.setText("");
lname.setText("");
classid.setText("");
classname.setText("");
pointgrade.setText("");
lettergrade.setText("");
studentid.requestFocus();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
小部件包裹Text()
。将左引号定位到Positioned
和top:
,右引用left:
bottom:
。并使用right:
包装中间文本,从Container
计算剩余大小并将固定大小设置为容器并将其放置在计算的坐标处。
我相信还有其他解决方案
答案 2 :(得分:0)
你总是可以做专栏 - &gt; [Expanded(text),Expanded(Container(),Expanded(text)]并根据需要调整空白框的flex。
还有容器(或列/行) - &gt;堆栈 - &gt; [Column(mainAxis start),Column(mainAxis end)]。
更聪明地工作,而不是更努力。 IntrinsicHeight小部件的计算成本很高,我不建议使用它。