如何根据设计正确对齐视图?
一位设计师为我的 Android 应用程序做了一些设计,这是一个 ListView 的设计(不是真正的,但想法相同..):
因此,在绿色区域的中间有一些文本,在橙色区域中有一个图像视图(可单击) ..),在蓝色区域的中间是另一个文本..这是1个列表视图..所以如果你滑动一行,另一行也会滑动相同的..(它们不是3个列表视图..)黄色区域是空的
如何对齐视图以便它适用于所有屏幕尺寸?如何使文本在绿色和蓝色区域居中?
谢谢
这是我使用的行的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="horizontal"
android:layout_height="wrap_content" android:paddingLeft="40dip"
android:paddingRight="40dip">
<TextView android:id="@+id/Start_Numbering" android:textSize="19.5sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0.3"
/>
<ImageView android:id="@+id/Start_ImageView"
android:layout_weight="0.1" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:src="@drawable/list_noaudioavailable"
></ImageView>
<TextView android:id="@+id/Start_Name" android:textColor="#a7e9fe"
android:textSize="21dip" android:layout_width="fill_parent"
android:layout_weight="0.6"
android:layout_height="wrap_content" />
这是 getView:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
convertView = mInflater.inflate(R.layout.start_row, null); //line 47
holder=new ViewHolder();
holder.tv_Name =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_PageNumber = (TextView)convertView.findViewById(R.id.Start_Numbering);
holder.im_Audio=(ImageView)convertView.findViewById(R.id.Start_ImageView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tv_Name.setText(Names[position]);
holder.tv_PageNumber.setText(Integer.toString(PageNumber[position]));
return convertView;
}
class ViewHolder {
TextView tv_Name;
TextView tv_PageNumber;
ImageView im_Audio;
}
但我得到的只是这个,为什么 tv_Name 没有显示?:
a designer made some design for my Android app, here is a design for a ListView (not the real one but the same idea..):
So in the middle of the green area there is some text, and in the orange area an imageview (clickable..), and in the middle of the blue area another text.. this is 1 listview.. so if you swipe one row the other also swipe the same.. (they arent 3 listviews..) The yellow area is empty
How do I align the views so it works on all screen sizes? How can I center the text in the green and blue area?
Thanks
Here is the xml of the row I used:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="horizontal"
android:layout_height="wrap_content" android:paddingLeft="40dip"
android:paddingRight="40dip">
<TextView android:id="@+id/Start_Numbering" android:textSize="19.5sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0.3"
/>
<ImageView android:id="@+id/Start_ImageView"
android:layout_weight="0.1" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:src="@drawable/list_noaudioavailable"
></ImageView>
<TextView android:id="@+id/Start_Name" android:textColor="#a7e9fe"
android:textSize="21dip" android:layout_width="fill_parent"
android:layout_weight="0.6"
android:layout_height="wrap_content" />
Here is getView:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
convertView = mInflater.inflate(R.layout.start_row, null); //line 47
holder=new ViewHolder();
holder.tv_Name =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_PageNumber = (TextView)convertView.findViewById(R.id.Start_Numbering);
holder.im_Audio=(ImageView)convertView.findViewById(R.id.Start_ImageView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tv_Name.setText(Names[position]);
holder.tv_PageNumber.setText(Integer.toString(PageNumber[position]));
return convertView;
}
class ViewHolder {
TextView tv_Name;
TextView tv_PageNumber;
ImageView im_Audio;
}
But all I get is this, why the tv_Name isnt being display?:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奥马尔,你的问题不太清楚,但我会尝试一下。
LinearLayout
在 row.xml 中,您将使用
它将有五个子元素
绿色文本字段,layout_weight=4
布局权重=1
要使文本居中,请使用适当的文本对齐属性。所有这些元素都应将layout_width定义为fill_parent。
Omar, your questions wasn't crystal clear, but I will give it a shot.
You use
In your row.xml, you would use
It will have five child elements
Green TextField with layout_weight=4
layout_weight=1
For centering the text use appropriate text align property. All of these elements should have layout_width defined as fill_parent.