滚动查看工作不正常的Android [英] Scroll View is not working properly Android
问题描述
我想创建一个像设计这个形象。
我想在左边和右边两个独立的滚动
我做了什么,我已经创建了一个主布局。在我正在膨胀在运行时的内部设计。所以不屑是正确的now.But我做了一些愚蠢的错误。因为那的滚动来了里面的布置。所以请参阅code和帮助我,我在新的Android
类
无效使用setData(){
flightResult =(的LinearLayout)findViewById(R.id.flightResultData);
LinearLayout.LayoutParams flightDetailsLayout =新LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
LayoutInflater吹气=(LayoutInflater)getBaseContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。 LinearLayout.LayoutParams forUnderLine =新LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
forUnderLine.setMargins(0,0,0,0); flightDetailsLayout.setMargins(0,40,0,0);
对(INT I = 0; I&; 13;我++){
TextView的行=新的TextView(本);
line.setBackgroundResource(R.layout.shape_line);
line.setLayoutParams(forUnderLine);
如果(ⅰ!= 0){
flightResult.addView(线);
}
的LinearLayout flightInformations =(的LinearLayout)inflater.inflate(R.layout.flight_details_layout,NULL);
flightLogo =(ImageView的)flightInformations.findViewById(R.id.onewayflightLogo);
flightCompany =(TextView中)flightInformations.findViewById(R.id.onewayflightName);
flightLogo.setImageResource(R.drawable.airindia);
flightCompany.setText(AirIndia); flightResult.addView(flightInformations);
}
TextView的哑=新的TextView(本);
dummy.setLayoutParams(flightDetailsLayout);
flightResult.addView(虚设);
}
主要布局(我在哪里infalting到flightResultData)
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向> <的LinearLayout
机器人:ID =@ + ID / mainLinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:背景=@绘制/ top_bg
机器人:方向=横向>
< ImageView的
机器人:ID =@ + ID / back_button
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ back_btn
机器人:layout_marginTop =5DP
机器人:layout_marginLeft =10dp/> <的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =10dp
机器人:layout_marginLeft =75dp
机器人:文字=@字符串/ flightHeader
机器人:文字颜色=@机器人:彩色/白/>
< / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID / flightDetailsLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =70dp
机器人:layout_below =@ + ID / mainLinearLayout
机器人:layout_centerHorizontal =真
机器人:背景=@绘制/ gray_bg123
机器人:方向=垂直>
<的LinearLayout
机器人:ID =@ + ID / innerflightDetailsLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向> <的TextView
机器人:ID =@ + ID /来自
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =12dp
机器人:paddingLeft =12dp
机器人:TEXTSIZE =12SP
机器人:文字=波士顿到旧金山,
机器人:文字样式=大胆/> <的TextView
机器人:ID =@ + ID / TRIPTYPE
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =12dp
机器人:文字=往返
机器人:TEXTSIZE =12SP/> < / LinearLayout中>
<的LinearLayout
机器人:ID =@ + ID / innerTripLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向> <的TextView
机器人:ID =@ + ID / tripDate
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:paddingLeft =12dp
机器人:TEXTSIZE =10SP
机器人:文字=2013年1月19日
机器人:文字样式=大胆/>
<的TextView
机器人:ID =@ + ID / paxText
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=1成人,0童车,澳婴儿
机器人:TEXTSIZE =12dp/>
< / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID /书
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_marginTop =5DP
机器人:方向=横向> <的TextView
机器人:ID =@ + ID / tripDate
机器人:layout_width =84dp
机器人:layout_height =WRAP_CONTENT
机器人:paddingLeft =12dp
机器人:文字=RS 10,2345
机器人:TEXTSIZE =10SP
机器人:layout_weight =1
机器人:文字样式=大胆/> < ImageView的
机器人:ID =@ + ID / bookBtn
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:重力=左
机器人:SRC =@绘制/书/> < / LinearLayout中> < / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID / sortFlightLayouts
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / flightDetailsLayout
机器人:背景=@绘制/ gray_bg123
机器人:方向=横向> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:方向=垂直> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=DEL-BLR
机器人:layout_marginLeft =6DP
机器人:layout_marginTop =5DP
机器人:文字样式=大胆/> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT 机器人:方向=横向> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:SRC =@绘制/ flight_icon_result/> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:layout_marginLeft =25dp
机器人:SRC =@绘制/时间/> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:layout_marginLeft =5DP
机器人:SRC =@绘制/卢比/>
< / LinearLayout中>
< / LinearLayout中>
<查看
机器人:layout_width =1DP
机器人:layout_height =60dp
机器人:背景=@机器人:彩色/ darker_gray/>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:背景=@绘制/ gray_bg123
机器人:方向=垂直> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=BLR-DEL
机器人:layout_marginLeft =6DP
机器人:layout_marginTop =5DP
机器人:文字样式=大胆/> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:SRC =@绘制/ flight_icon_result/> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:layout_marginLeft =25dp
机器人:SRC =@绘制/时间/> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5DP
机器人:layout_marginLeft =5DP
机器人:SRC =@绘制/卢比/>
< / LinearLayout中>
< / LinearLayout中>
< / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID / flightResultData
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / sortFlightLayouts
机器人:layout_marginLeft =8DP
机器人:方向=垂直>
< / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID / footerLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentBottom =真
机器人:方向=横向
机器人:背景=@绘制/ top_bg> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:比重=中心
机器人:layout_marginTop =5DP
机器人:SRC =@绘制/过滤器/>
< ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:比重=中心
机器人:layout_marginTop =5DP
机器人:SRC =@绘制/排序/>
< / LinearLayout中>
< / RelativeLayout的>
details_layout.xml
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / mainResultLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:baselineAligned =假
机器人:比重=中心
机器人:方向=垂直> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向> <滚动型
机器人:ID =@ + ID / returnScrollView
机器人:layout_width =0dp
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1> <的LinearLayout
机器人:ID =@ + ID / oneWayResultData
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:方向=横向> <的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直> < ImageView的
机器人:ID =@ + ID / onewayflightLogo
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =3DP
机器人:SRC =@绘制/ SpiceJet航空公司/> <的TextView
机器人:ID =@ + ID / onewayflightName
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=SpiceJet航空公司/> <的TextView
机器人:ID =@ + ID / onewayflightNumber
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=9W - 496/>
< / LinearLayout中> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =match_parent
机器人:方向=垂直> <的TextView
机器人:ID =@ + ID / onewayflightTime
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
机器人:layout_marginTop =6DP
安卓的minlines =1
机器人:文字=06:00 - 7:05
机器人:TEXTSIZE =12dp/> <的TextView
机器人:ID =@ + ID / onewayflightDuration
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
安卓的minlines =1
机器人:文字=1小时35米| NON STOP
机器人:TEXTSIZE =10dp/> <的TextView
机器人:ID =@ + ID / onewayflightAmount
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
安卓的minlines =1
机器人:文字=RS 20,0000
机器人:TEXTSIZE =12dp/>
< / LinearLayout中>
< / LinearLayout中>
< /滚动型> <查看
机器人:layout_width =1DP
机器人:layout_height =60dp
机器人:背景=@机器人:彩色/ darker_gray/> <滚动型
机器人:ID =@ + ID / returnScrollView
机器人:layout_width =0dp
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1> <的LinearLayout
机器人:ID =@ + ID / returnResultData
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:方向=横向> <的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直> < ImageView的
机器人:ID =@ + ID / returnflightLogo
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =3DP
机器人:SRC =@绘制/ SpiceJet航空公司/> <的TextView
机器人:ID =@ + ID / returnflightName
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =3DP
机器人:文字=辣妹喷/> <的TextView
机器人:ID =@ + ID / returnflightNumber
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =3DP
机器人:文字=8W - 356/>
< / LinearLayout中> <的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =match_parent
机器人:方向=垂直> <的TextView
机器人:ID =@ + ID / returnflightTime
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
机器人:layout_marginTop =6DP
安卓的minlines =1
机器人:文字=06:00 - 7:05
机器人:TEXTSIZE =12SP/> <的TextView
机器人:ID =@ + ID / returnflightDuration
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
安卓的minlines =1
机器人:文字=1小时35米| NON STOP
机器人:TEXTSIZE =10SP/> <的TextView
机器人:ID =@ + ID / returnflightAmount
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
安卓的minlines =1
机器人:文字=RS 20,0000
机器人:TEXTSIZE =12SP/>
< / LinearLayout中>
< / LinearLayout中>
< /滚动型>
< / LinearLayout中>< / LinearLayout中>
我有一个看布局XML和发现你的问题。在一个布局你试图同时定义scrollviews及其内容。你不希望被这样做。我也建议你不想要一个滚动视图,而是一个列表视图。
看看这一>教程如何创建自定义列表视图的内容,并创建一个arrayadapter用数据来填充它。
这是你的主要布局如何看一个例子:
<?XML版本=1.0编码=UTF-8&GT?;< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的LinearLayout
机器人:ID =@ + ID / llHeader
机器人:方向=垂直
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的LinearLayout
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =4
机器人:方向=横向> < ListView控件
机器人:ID =@ + ID / lvDepartures
机器人:layout_weight =1
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT/>
< ListView控件
机器人:ID =@ + ID / lvArrivals
机器人:layout_weight =1
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT/> < / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID / llFooter
机器人:方向=垂直
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/>< / LinearLayout中>
这给你动态加权,所以它看起来在比例1中的任何设备屏幕上同样的三个垂直部分:4:1。然后,中间段在中间拆了下来两个列表视图,它们是独立的滚动,你可以使用适配器填充。
然后,你要创建飞行
单个布局 <的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> < ImageView的
机器人:layout_width =75sp
机器人:layout_height =75sp
机器人:layout_marginRight =10SP
机器人:layout_marginTop =5SP
机器人:layout_marginBottom =5SP
机器人:ID =@ + ID / ivDemoIcon
机器人:layout_alignParentTop =真
机器人:layout_alignParentLeft =真/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=center_vertical
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
机器人:文字=演示名
机器人:layout_marginTop =20SP
机器人:ID =@ + ID / tvDemoName
机器人:layout_toRightOf =@ + ID / ivDemoIcon
机器人:layout_toLeftOf =@ + ID / ivChevron/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_toRightOf =@ + ID / ivDemoIcon
机器人:layout_toLeftOf =@ + ID / ivChevron
机器人:文字=日期版本
机器人:ID =@ + ID / tvDateVersion
机器人:textAppearance =机器人:ATTR / textAppearanceSmall
机器人:layout_below =@ + ID / tvDemoName/> < ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / ivChevron
机器人:layout_alignTop =@ + ID / ivDemoIcon
机器人:layout_alignParentRight =真
机器人:layout_alignBottom =@ + ID / ivDemoIcon/>
< / RelativeLayout的>
本布置有两个图标以及文字的三段空间很好地奠定了。您可以将这些有关,当你想和你想要的信息创建布局。总是试图使布局尽可能通用,所以你可以使用它一遍又一遍。
您就可以使用您的适配器来填充每个列表视图与这种飞行的布局的一个实例,每个航班的每个元素(我已经懒得去调整它是一个飞行的布局像你,但你应该得到的依据)。
您可以创建一个页眉和页脚布局其中textviews和imageviews等,可以在运行时设置accoring你有什么航班信息。对于航班信息,我会强烈建议使用访问一个单独的数据类从任何地方的信息存储在的ArrayList(列表视图适配器等用的ArrayList发挥得很好,你可以做各种很酷的事情像排序和过滤)
巧编码的优点是使一切动态和可重复使用的,你可以。不要去硬编码的事物或同一事物产生大量的布局,再利用和回收!将使您的工作更加容易。希望这有助于
I Want to create a design like this image .
I want independent scroll on both left and right side
What i have done that i have created a main layout .In that i am inflating the inner design at run time .So the deign is proper now.But i have done some silly mistake .Because of that the the scroll is coming inside the layout .So please see the code and help me i am new in android
Class
void setData(){
flightResult=(LinearLayout)findViewById(R.id.flightResultData);
LinearLayout.LayoutParams flightDetailsLayout = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout.LayoutParams forUnderLine = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
forUnderLine.setMargins(0,0, 0, 0);
flightDetailsLayout.setMargins(0, 40, 0, 0);
for(int i=0;i < 13;i++){
TextView line=new TextView(this);
line.setBackgroundResource(R.layout.shape_line);
line.setLayoutParams(forUnderLine);
if(i!=0){
flightResult.addView(line);
}
LinearLayout flightInformations=(LinearLayout)inflater.inflate(R.layout.flight_details_layout, null);
flightLogo=(ImageView)flightInformations.findViewById(R.id.onewayflightLogo);
flightCompany = (TextView)flightInformations.findViewById(R.id.onewayflightName);
flightLogo.setImageResource(R.drawable.airindia);
flightCompany.setText("AirIndia");
flightResult.addView(flightInformations);
}
TextView dummy=new TextView(this);
dummy.setLayoutParams(flightDetailsLayout);
flightResult.addView(dummy);
}
Main Layout (where i am infalting to flightResultData)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/mainLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/top_bg"
android:orientation="horizontal" >
<ImageView
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back_btn"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="75dp"
android:text="@string/flightHeader"
android:textColor="@android:color/white" />
</LinearLayout>
<LinearLayout
android:id="@+id/flightDetailsLayout"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="@+id/mainLinearLayout"
android:layout_centerHorizontal="true"
android:background="@drawable/gray_bg123"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/innerflightDetailsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingLeft="12dp"
android:textSize="12sp"
android:text="Boston to San Fransisco, "
android:textStyle="bold" />
<TextView
android:id="@+id/tripType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="RoundTrip"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/innerTripLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/tripDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:textSize="10sp"
android:text="19 Jan 2013 "
android:textStyle="bold"/>
<TextView
android:id="@+id/paxText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="for 1 Adults,0 Childs,O Infants"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/Book"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/tripDate"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:text="Rs 10,2345 "
android:textSize="10sp"
android:layout_weight="1"
android:textStyle="bold" />
<ImageView
android:id="@+id/bookBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:src="@drawable/book" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/sortFlightLayouts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/flightDetailsLayout"
android:background="@drawable/gray_bg123"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DEL-BLR"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/flight_icon_result" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="25dp"
android:src="@drawable/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:src="@drawable/rupee" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="60dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/gray_bg123"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLR-DEL"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/flight_icon_result" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="25dp"
android:src="@drawable/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:src="@drawable/rupee" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/flightResultData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sortFlightLayouts"
android:layout_marginLeft="8dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/footerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@drawable/top_bg" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
android:src="@drawable/filter" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="5dp"
android:src="@drawable/sort" />
</LinearLayout>
</RelativeLayout>
details_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainResultLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ScrollView
android:id="@+id/returnScrollView"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/oneWayResultData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/onewayflightLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:src="@drawable/spicejet" />
<TextView
android:id="@+id/onewayflightName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SpiceJet" />
<TextView
android:id="@+id/onewayflightNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9W - 496" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/onewayflightTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="6dp"
android:minLines="1"
android:text="06:00 - 7:05"
android:textSize="12dp" />
<TextView
android:id="@+id/onewayflightDuration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:minLines="1"
android:text="1h 35m | Non Stop"
android:textSize="10dp" />
<TextView
android:id="@+id/onewayflightAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:minLines="1"
android:text="Rs 20,0000"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<View
android:layout_width="1dp"
android:layout_height="60dp"
android:background="@android:color/darker_gray" />
<ScrollView
android:id="@+id/returnScrollView"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/returnResultData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/returnflightLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:src="@drawable/spicejet" />
<TextView
android:id="@+id/returnflightName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="Spice jet" />
<TextView
android:id="@+id/returnflightNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="8W - 356" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/returnflightTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="6dp"
android:minLines="1"
android:text="06:00 - 7:05"
android:textSize="12sp" />
<TextView
android:id="@+id/returnflightDuration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:minLines="1"
android:text="1h 35m | Non Stop"
android:textSize="10sp" />
<TextView
android:id="@+id/returnflightAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:minLines="1"
android:text="Rs 20,0000"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
I've had a look at the layout XML and have found your problem. In one layout you are trying to define both scrollviews and their contents. You don't want to be doing this. I would also suggest you don't want a scrollview, but a listview.
Take a look at This tutorial on how to create listviews with custom contents and create an arrayadapter to populate it with data.
This is an example of how your main layout could look:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/llHeader"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="4"
android:orientation="horizontal">
<ListView
android:id="@+id/lvDepartures"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<ListView
android:id="@+id/lvArrivals"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="@+id/llFooter"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
This gives you three vertical sections weighted DYNAMICALLY so it looks the same on any device screen in proportions 1:4:1. Then the middle section is split down the middle with two listviews which are independently scrollable which you can populate using an adapter.
Then you want to create a SINGLE layout for "a flight"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="75sp"
android:layout_height="75sp"
android:layout_marginRight="10sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:id="@+id/ivDemoIcon"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Demo Name"
android:layout_marginTop="20sp"
android:id="@+id/tvDemoName"
android:layout_toRightOf="@+id/ivDemoIcon"
android:layout_toLeftOf="@+id/ivChevron"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ivDemoIcon"
android:layout_toLeftOf="@+id/ivChevron"
android:text="Date Version"
android:id="@+id/tvDateVersion"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="@+id/tvDemoName"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ivChevron"
android:layout_alignTop="@+id/ivDemoIcon"
android:layout_alignParentRight="true"
android:layout_alignBottom="@+id/ivDemoIcon"/>
</RelativeLayout>
This layout has space for two icons as well as three sections of text nicely layed out. You can move these about and create the layout as you want with the information you want. Always try and make layouts as generic as possible so you can use it over and over.
You can then use your adapter to populate each element of each listview for each flight with an instance of this "flight" layout (I've been too lazy to tweak it to be a flight layout like yours but you should get the gist).
You can then create a header and footer layout which the textviews and imageviews etc can be set at runtime accoring to what flight information you have. For the flight information, I would strongly suggest using a singleton data class accessible from anywhere and store the information in ArrayLists (Listview adapters etc play VERY nicely with arraylists and you can do all sorts of cool things like sorting and filtering)
The beauty of clever coding is making everything as dynamic and reusable as you can. Don't go hardcoding things or creating lots of layouts for the same thing, Reuse and recycle! Will make your job much easier. Hope this has helped
这篇关于滚动查看工作不正常的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!