Horizontal Scroll View inside LinearLayout - Android - android

I have a custom list. I am trying to scroll horizontally only specific part. For Instance, in the below image iam trying to scroll horizontally just the orange box.
Here is my XML Layout: In the XML layout the Orange box starts "android:id="#+id/projected"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="63dp"
android:layout_marginLeft="0dp"
android:background="#drawable/bkg_img_fullcell"
android:orientation="horizontal" >
<!-- Left Column -->
<LinearLayout
android:id="#+id/widget_lineupview_playerdata_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:layout_toRightOf="#+id/sideView"
android:gravity="center_vertical"
android:layout_toLeftOf="#+id/projected"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<!-- rel 1 -->
<LinearLayout
android:id="#+id/playername1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_toRightOf="#+id/sideView">
<com.cbssports.nflapp.ffb.MyTextViewBold
android:id="#+id/widget_lineupview_playerdata_playername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:inputType="text|textNoSuggestions"
android:layout_marginLeft="5dp"
android:maxLines="1"
android:text=""
android:textColor="#08233e"
android:textSize="15dp" />
</LinearLayout>
<!-- rel 2 -->
<LinearLayout
android:id="#+id/widget_lineupview_playerdata_playerStatsIconContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="#+id/playername1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/widget_lineupview_playerdata_statusIconSuspended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:src="#drawable/btn_s"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="#+id/sideView" >
<TextView
android:id="#+id/widget_lineupview_playerdata_playerPositionTeam"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:inputType="text|textNoSuggestions"
android:maxLines="1"
android:text=""
android:textColor="#333333"
android:textSize="12dp" />
<ImageView
android:id="#+id/widget_lineupview_playerdata_startingPitcherStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:src="#drawable/btn_baseballgraphic"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/sideView"
android:layout_width="#dimen/widget_lineup_table_status_column_width"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:layout_alignParentLeft="true"
android:background="#drawable/bkg_img_rosterpos"
android:gravity="center" >
<!-- <Button -->
<com.cbssports.nflapp.ffb.VerticalTextView
android:id="#+id/widget_lineupview_playerdata_playerStatusButton"
android:layout_width="21dp"
android:layout_height="60dp"
android:layout_margin="0dp"
android:padding="0dp"
android:textColor="#004a8e"
android:textSize="11dp"
android:textStyle="bold"
android:gravity="bottom|center" />
</LinearLayout>
***<LinearLayout
android:id="#+id/projected"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_toLeftOf="#+id/percentStarted">
<TextView
android:id="#+id/widget_lineupview_player_h2h_stats_started_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
<LinearLayout
android:id="#+id/percentStarted"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dp">
<TextView
android:id="#+id/widget_lineupview_player_projected_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>***
</RelativeLayout>

Thank You g00dy, i can able to solve it by adding one LinearLayout inside horizontalScrollView it.
Here is my solution.
<HorizontalScrollView
android:id="#+id/horizontalScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:scrollbars="none">
<LinearLayout
android:id="#+id/horizontalScroll_linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true" >
<LinearLayout
android:id="#+id/projected"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_toLeftOf="#+id/percentStarted">
<TextView
android:id="#+id/widget_lineupview_player_h2h_stats_started_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
<LinearLayout
android:id="#+id/percentStarted"
android:layout_width="wrap_content"
android:layout_height="#dimen/widget_lineup_table_row_height"
android:background="#drawable/bkg_img_whiteoverlay"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dp">
<TextView
android:id="#+id/widget_lineupview_player_projected_custom"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
android:textSize="16dp"
android:textColor="#333333" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>

You can also set the LinearLayout fillViewport to true and foregroundGravity to true (not sure if this last is necessary), and set the child LinearLayout gravity to right:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="#dimen/IconM"
android:id="#+id/account_food_scroll"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/client_add_button_layout"
android:foregroundGravity="right"
android:layout_marginLeft="#dimen/PadM"
android:fillViewport="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="#dimen/IconM"
android:id="#+id/account_food_layout"
android:gravity="right">
</LinearLayout>
</HorizontalScrollView>

Related

How I can put "Imagenview" under all the elements?

Hi, I commented that I have this layout and if you can see there is a line on the right which should go below the text
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_promocion_item0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#363636"
android:padding="10dip" >
<LinearLayout
android:id="#+id/contenido"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:id="#+id/contenido_Nombre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:orientation="horizontal"
>
<TextView
android:id="#+id/nombre_promo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vodka + Nectar"
android:textColor="#ffffff"
android:textSize="25sp"
android:tag="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/contenido_precio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal" >
<ImageView
android:id="#+id/separador_lateral"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/vertical"
android:layout_gravity="left"/>
<TextView
android:id="#+id/precio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2200"
android:textColor="#ffffff"
android:textSize="24dp"
/>
</LinearLayout>
<ImageView
android:id="#+id/separador"
android:layout_width="0dp"
android:layout_height="19dp"
android:layout_weight=".50"
android:src="#drawable/divierblanco"
android:layout_alignParentLeft="true"/>
</LinearLayout>
</LinearLayout>
.. so is something like:
NAME: PRICE
I can not locate the image below the text .... Can you help me?
You have way too many nested LinearLayouts, IMHO, which can be bad for performance and decrease readability. I would use a RelativeLayout and 1 nested LinearLayout
<RelativeLayout
...>
<LinearLayout
android:id="#+id/someId"
....
<TextView
...>
<ImageView
...>
<TextView
...>
</LinearLayout>
<ImageView
android:layout_below="id/someId"
...>
Something like this should work.
Alternatively if this doesn't work for you, then placing that ImageVIew outside of the first child LinearLayout should also work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_promocion_item0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#363636"
android:padding="10dip" >
<LinearLayout
android:id="#+id/contenido"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/contenido_Nombre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:orientation="horizontal" >
<TextView
android:id="#+id/nombre_promo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vodka + Nectar"
android:textColor="#ffffff"
android:textSize="25sp"
android:tag="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/contenido_precio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal" >
<ImageView
android:id="#+id/separador_lateral"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/vertical"
android:layout_gravity="left"/>
<TextView
android:id="#+id/precio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2200"
android:textColor="#ffffff"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/separador"
android:layout_width="0dp"
android:layout_height="19dp"
android:layout_weight=".50"
android:src="#drawable/divierblanco"
android:layout_alignParentLeft="true"/> // this doesn't do anything in a LinearLayout
</LinearLayout>
Your imageView (with the id separador) is inside a linearLayout with an orientation set to "horizontal". Move the imageView to the outermost linearlayout like so:
EDIT: The xml that's displayed below is completely different than what I typed in my answer. What's up with that? Regardless, move the imageView down an element.
<LinearLayout
android:id="#+id/contenido"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/contenido_Nombre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:orientation="horizontal" >
<TextView
android:id="#+id/nombre_promo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="bold"
android:text="Vodka + Nectar"
android:textColor="#ffffff"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/contenido_precio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal" >
<ImageView
android:id="#+id/separador_lateral"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="left"
android:src="#drawable/vertical" />
<TextView
android:id="#+id/precio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2200"
android:textColor="#ffffff"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/separador"
android:layout_width="0dp"
android:layout_height="19dp"
android:layout_alignParentLeft="true"
android:layout_weight=".50"
android:src="#drawable/divierblanco" /></LinearLayout>

Calling of another XML by View and Layout

Every body I want to call another XML in my activity , i called my main xml as given below
setContentView(R.layout.main);
and my xml file is as follow-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/appbg"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/ll2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- listview -->
<ImageView
android:id="#+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:contentDescription="#drawable/logo12"
android:src="#drawable/logo12" />
<LinearLayout
android:id="#+id/homeLin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="right" >
<Button
android:id="#+id/btnCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/cart_icon" />
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/home" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/searchLin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/search"
android:textColor="#color/Black"
android:textSize="15sp" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/cross1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="5dp"
android:contentDescription="#drawable/search"
android:src="#drawable/search" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linSortby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvsortby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sortby"
android:textColor="#color/Blue"
android:textSize="13sp" />
<TextView
android:id="#+id/tvPriceLH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priceLH"
android:textColor="#color/Blue"
android:textSize="13sp" />
<TextView
android:id="#+id/tvPriceHL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="#string/priceHL"
android:textColor="#color/Blue"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linPagingupper"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linPaging"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:contentDescription="#drawable/prev"
android:src="#drawable/prev" />
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/buttonbackground"
android:text="#string/n1"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n2"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n3"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n4"
android:textColor="#color/Blue"
android:textSize="12sp" />
<TextView
android:id="#+id/tv5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonbackground"
android:text="#string/n5"
android:textColor="#color/Blue"
android:textSize="12sp" />
<!-- button -->
<ImageView
android:id="#+id/imgNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:contentDescription="#drawable/next"
android:src="#drawable/next" />
</LinearLayout>
<TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/n1"
android:textColor="#color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/listViewResult"
android:layout_width="fill_parent"
android:layout_height="320dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bluegrad"
android:gravity="bottom"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:contentDescription="#drawable/contact"
android:src="#drawable/contact" />
<LinearLayout
android:id="#+id/bottomLin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageView
android:id="#+id/imgHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:contentDescription="#drawable/home"
android:src="#drawable/home" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/add_other_xml"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
and i want to call another activity by following code-
LinearLayout lin_lay_add_paynow =
(LinearLayout)findViewById(R.id.add_other_xml);
View pay_now_view = getLayoutInflater().inflate(R.layout.pay_now_btn, null);
lin_lay_add_paynow.addView(pay_now_view);
TextView btn_pay_now = (TextView) pay_now_view.findViewById(R.id.btn_paynow);
btn_pay_now.setText("mlsdmlsm");
and my pay_now_btn.xml is as follow
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/btn_paynow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
And problem is that i am doing every thing in correct manner . Then why my textview is not appearing . No error no exception then i am not able to see my textview of pay_now_btn.xml
Thanks in advance to all.
You have setContentView(R.layout.main).
And you are inflating a view. But the inflated view is not added to the layout.
Have a another LinearLayout in your main.xml. Place this linear layout to the required position or you can use Relativelayout.
Initialize it in onCreate
LinearLayout ll = LinearLayout findViewById(R.id.ll);
Now add the inflated view to linearlayout
ll.addView(pay_now_view);
Edit:
You can add the infalted view as a footer to listview as
list.addFooterView(pay_now_view );
You have not added the view into a layout in your main.xml
Create a layout in your main.xml
In your code
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(pay_now_view);
Hope this works. Let me know if you face any problem
CODE :
Add this at bottom of main.xml before closing the last tag
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
</LinearLayout>
In your Activity after inflating and setText:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.addView(pay_now_view);

Scroll View is not working properly Android

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

Slim Spinner when i use FILL_PARENT (or MATCH_PARENT) as WIDTH

i've a strange problem when i set android:layout_width="fill_parent" in my Spinner:
the clickable area is reduced to a line (red square) and only pressing on this line is possibile show the elements of the Spinner:
if i use android:layout_width="wrap_content" i obtain the correct area:
i would like the same thing using "fill_parent"
The elements of the Spinner are correctly visualized.. The only problem is clicking on the Spinner.
Which is the possible problem?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#040404"
android:gravity="center"
android:paddingTop="2dp"
android:weightSum="4" >
<TextView
android:id="#+id/mpp_movimento_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_verde"
android:gravity="center"
android:text="#string/Movimento"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_eccesso_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_rossa"
android:gravity="center"
android:text="#string/Eccesso"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_fermo_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_grigia"
android:gravity="center"
android:text="#string/Fermo"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_ripristina_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ripristina_mappa_40x40"
android:gravity="center"
android:text="#string/Ripristina"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/mpp_automezzi_visualizzati_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:gravity="center"
android:paddingTop="5dp"
android:text="#string/AutomezziVisualizzati"
android:textColor="#color/white"
android:textSize="17sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingTop="5dp" >
<FrameLayout
android:id="#+id/mpp_spinner_frame_fly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/mpp_cerca_btn" >
<Spinner
android:id="#+id/mpp_spinner_spn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="17sp" />
</FrameLayout>
<ImageButton
android:id="#+id/mpp_cerca_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#drawable/selector_white_btn"
android:contentDescription="#string/DescrizioneCerca"
android:gravity="center"
android:onClick="doCerca"
android:src="#drawable/cerca" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#040404"
android:gravity="center" >
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/mpp_mappa_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Try setting your Spinner's parent's height to match_parent. And also do you really need such layout? There is no need to place spinner in FrameLayout, try setting spinners's weight to 1 and replace RelativeLayout with LinearLayout

GridLayout - Aligning Element

I am trying to reduce the space between 2 columns, have tried using negative margins, but did not work. Is there a way to bring the 2 elements in the image closer ?
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
android:alignmentMode="alignBounds"
android:columnOrderPreserved="false"
android:layout_gravity="center"
android:orientation="horizontal"
android:stretchMode="columnWidth"
android:background="#color/orange"
android:textSize="12sp"
android:columnCount="8">
<ImageButton
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="1"
android:layout_gravity="left"
android:src="#drawable/settings" />
<TextView
android:id="#+id/currentCityName"
android:layout_column="2"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City name"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"
/>
<ImageButton
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="7"
android:layout_columnSpan="1"
android:layout_gravity="right"
android:src="#drawable/reload" />
<ImageView
android:id="#+id/currentWeatherImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="8"
android:layout_rowSpan="3"
android:layout_gravity="center_horizontal"
android:src="#drawable/cloud" />
<ImageView
android:id="#+id/humidityIcon"
android:layout_width="20dp"
android:paddingTop="10dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_marginRight="0dp"
android:layout_gravity="left"
android:background="#000000"
android:src="#drawable/humidity" />
<TextView
android:id="#+id/humidity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:paddingTop="10dp"
android:paddingLeft="0dp"
android:layout_marginLeft="0dp"
android:layout_gravity="left"
android:background="#FFFFFF"
/>
<TextView
android:id="#+id/temperature"
android:layout_columnSpan="4"
android:layout_rowSpan="2"
android:textSize="49sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_gravity="center_horizontal"/>
<ImageView
android:id="#+id/windSpeedIcon"
android:layout_width="30dp"
android:layout_marginRight="1dp"
android:paddingRight="1dp"
android:layout_gravity="right"
android:src="#drawable/wind" />
<TextView
android:id="#+id/windSpeed"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
<!-- android:layout_width="40dp" -->
<TextView
android:id="#+id/precipitationIcon"
android:textSize="28sp"
android:layout_width="40dp"
/>
<TextView
android:id="#+id/precipitation"
android:layout_column="0"
android:textSize="13sp"
android:layout_width="40dp"
/>
<TextView
android:id="#+id/windDirection16Point"
android:textSize="13sp"
android:layout_width="80dp"
android:layout_columnSpan="2"
/>
<TextView
android:id="#+id/weatherDescription"
android:layout_gravity="center_horizontal"
android:layout_row="7"
android:layout_columnSpan="8"/>
<TextView
android:id="#+id/section_label"
android:layout_margin="5dp"
android:layout_columnSpan="8" />
<EditText
android:minLines="4"
android:maxLines="4"
android:id="#+id/edit"
android:layout_columnSpan="8"/>
I suggest implementing the entire view using a RelativeLayout, should be the best solution for the entire view.
You are tackling the wrong problem – you are asking how to reduce the space between columns in a grid layout, but maybe you should’t have used such a layout in the first place!
What you should have been using for your specific layout, is a combination of relative positioning and compound drawables (here, with android:drawableStart).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="80dp"
android:background="#d89018"
android:paddingBottom="4dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp"
>
<TextView
android:id="#+id/temperature"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="25 ℃"
android:textColor="#fff"
android:textSize="49sp"
/>
<TextView
android:id="#+id/humidity"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:drawableStart="#drawable/humidity"
android:gravity="center_vertical"
android:text="83 %"
android:textColor="#fff"
/>
<TextView
android:id="#+id/windSpeed"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:drawableStart="#drawable/wind"
android:gravity="center_vertical"
android:text="19 km/h"
android:textColor="#fff"
/>
<TextView
android:id="#+id/precipitation"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:drawableStart="#drawable/precipitation"
android:gravity="center_vertical"
android:text="0.1 mm"
android:textColor="#fff"
/>
<TextView
android:id="#+id/windDirection16Point"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="#id/windSpeed"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:drawableStart="#drawable/windDirection"
android:gravity="center_vertical"
android:text="NNW"
android:textColor="#fff"
/>
</RelativeLayout>
Not only this layout is simpler, you also let Android take care of all the spacing for you. To change the spacing between the compound drawable and the text, use android:drawablePadding in the layout’s code above; in Java code, that would be TextView.setCompoundDrawablePadding).
Icons used for the sample: water, windsock, rainy-weather and wind-rose.
I think what's happening is that your Views are being stretched because they are trying to match the width of another view in their columns.
Try decreasing the columnSpan of your Views or separate your layout into two separate GridLayouts.
Or, consider using a different layout altogether. I would recommend RelativeLayout here instead of GridLayout, but I don't know how this fits into a larger window.
try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:id="#+id/col1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2.4"
>
<LinearLayout
android:id="#+id/col1_row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="83%"/>
</LinearLayout>
<LinearLayout
android:id="#+id/col1_row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.0mm"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/col2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2.0"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="25'"
android:textSize="50dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/col3"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2.4"
>
<LinearLayout
android:id="#+id/col3_row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="19Km"/>
</LinearLayout>
<LinearLayout
android:id="#+id/col3_row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NNW"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I think you should change usedefaultMargins to false and give your own margins to the elements.
android:useDefaultMargins="false";

Categories

Resources