Android, listView, my text does not fit as wished - android

I am trying to make a ListView with 2 TextView and 2 ImageViews.
I want that "Location" TextView is under the "name" TextView and not at the right!
Here's the code so far of the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:height="?android:attr/listPreferredItemHeight"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="2px"
android:background="?android:attr/listDivider" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/list_item_widget_text"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical" />
<TextView
android:id="#+id/widget42"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Location"
android:layout_below="#+id/list_item_widget_text"/>
<ImageView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:src="#drawable/list_vertical_divider" />
<ImageView
android:id="#+id/list_item_widget_edit"
android:background="#drawable/list_item_widget_bg"
android:src="#android:drawable/ic_menu_edit"
android:layout_height="fill_parent"
android:layout_width="50dip"/>
<ImageView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:src="#drawable/list_vertical_divider" />
<ImageView
android:id="#+id/list_item_widget_delete"
android:background="#drawable/list_item_widget_bg"
android:src="#android:drawable/ic_menu_delete"
android:layout_height="fill_parent"
android:layout_width="50dip" />
</LinearLayout>
</LinearLayout>
Thank you in advance!

Wrap the 2 TextView in a LinearLayout like this
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/list_item_widget_text"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical" />
<TextView
android:id="#+id/widget42"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Location"
android:layout_below="#+id/list_item_widget_text"/>
<LinearLayout>

Though Apoorv's method is nice too, I would prefer using a RelativeLayout instead of a LinearLayout for that, it would give you more flexibility:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:height="?android:attr/listPreferredItemHeight"
android:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="2px"
android:background="?android:attr/listDivider" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/list_item_widget_text"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:gravity="center_vertical" />
<TextView
android:id="#+id/widget42"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Location"
android:layout_below="#+id/list_item_widget_text"/>
<ImageView
android:id="#+id/divider1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/list_item_widget_edit"
android:src="#drawable/list_vertical_divider" />
<ImageView
android:id="#+id/list_item_widget_edit"
android:background="#drawable/list_item_widget_bg"
android:src="#android:drawable/ic_menu_edit"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/divider2"
android:layout_width="50dip"/>
<ImageView
android:id="#+id/divider2"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/list_item_widget_delete"
android:src="#drawable/list_vertical_divider" />
<ImageView
android:id="#+id/list_item_widget_delete"
android:background="#drawable/list_item_widget_bg"
android:src="#android:drawable/ic_menu_delete"
android:layout_alignParentRight="true"
android:layout_height="fill_parent"
android:layout_width="50dip" />
</RelativeLayout>
</LinearLayout>

Related

Make FrameLayout element scrollable

I am working on adapting an app which was designed for a larger vertical screen dimension (1200px) to a device with a smaller size (vertical=800px). I've managed to get things displaying properly by editing the layout XML files--except for one thing. As you can see, the crossword puzzle is cut off at the bottom. Its original dimensions in the layout were 570x570px. At that size, the lower part of the puzzle ended up peeking out from behind the keyboard.
After resizing both the keyboard and the clue drop-down at the top of the screen so they work properly, I'm left with a vertical space of 390px for the puzzle. Absent any other ideas, I've been trying to implement scrolling in that FrameLayout, following several examples such as Scrollable FrameLayout.
I can't seem to get it to work. My knowledge of layout is sketchy. Can anyone suggest a solution or a different approach?
(the puzzle layout on the screen is given in line 6)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="bottom|center" android:orientation="vertical" android:background="#color/root_background" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout android:gravity="top|center" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">
<FrameLayout android:gravity="top|center" android:orientation="vertical" android:id="#id/field_container" android:paddingTop="160.0px" android:layout_width="600.0px" android:layout_height="wrap_content">
<com.encore.crossword.view.CrosswordView android:layout_gravity="top|center" android:id="#id/crosswordView" android:layout_width="570.0px" android:layout_height="390.0px" />
<LinearLayout android:gravity="center" android:id="#id/difficulty_layout" android:paddingTop="146.0px" android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_gravity="center" android:orientation="vertical" android:background="#drawable/c_dialog_box" android:paddingLeft="30.0px" android:paddingTop="30.0px" android:paddingRight="30.0px" android:paddingBottom="20.0px" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:textAppearance="#style/DialogHeader" android:gravity="center" android:id="#id/TextViewGameOver" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Game Difficulty" />
<RadioGroup android:gravity="left|center" android:orientation="vertical" android:id="#id/RadioGroupDifficulty" android:paddingTop="6.0px" android:paddingBottom="6.0px" android:layout_width="fill_parent" android:layout_height="wrap_content">
<RadioButton android:textAppearance="#style/ButtonTextMain" android:textColor="#color/button_radio" android:id="#id/RadioButtonEasy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false" android:button="#drawable/sudoku_radio_button" android:text="#string/easy" android:width="160.0px" />
<RadioButton android:textAppearance="#style/ButtonTextMain" android:textColor="#color/button_radio" android:id="#id/RadioButtonMedium" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="#drawable/sudoku_radio_button" android:text="#string/medium" android:width="160.0px" />
<RadioButton android:textAppearance="#style/ButtonTextMain" android:textColor="#color/button_radio" android:id="#id/RadioButtonHard" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="#drawable/sudoku_radio_button" android:text="#string/hard" android:width="160.0px" />
<RadioButton android:textAppearance="#style/ButtonTextMain" android:textColor="#color/button_radio" android:id="#id/RadioButtonExtreme" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="#drawable/sudoku_radio_button" android:text="#string/themeless" android:width="160.0px" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<LinearLayout android:gravity="top|center" android:orientation="vertical" android:id="#id/clue_container" android:background="#drawable/cross_top_dialog_box" android:paddingLeft="5.0px" android:paddingRight="5.0px" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:gravity="top|center" android:orientation="vertical" android:id="#id/mini_clue_container" android:paddingLeft="5.0px" android:paddingRight="5.0px" android:visibility="visible" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">
<LinearLayout android:id="#id/ClueTop1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:textAppearance="#style/ClueInfoText" android:id="#id/TextViewClueWordNumber1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" android:layout_weight="1.0" />
<TextView android:textAppearance="#style/ClueInfoText" android:gravity="right" android:id="#id/TextViewClueWordLength1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" android:layout_weight="1.0" />
</LinearLayout>
<TextView android:textAppearance="#style/ClueText" android:id="#id/TextViewClue1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10.0px" android:text="" android:lines="2" />
<LinearLayout android:id="#id/ClueTop2" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:textAppearance="#style/ClueInfoText" android:id="#id/TextViewClueWordNumber2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" android:layout_weight="1.0" />
<TextView android:textAppearance="#style/ClueInfoText" android:gravity="right" android:id="#id/TextViewClueWordLength2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" android:layout_weight="1.0" />
</LinearLayout>
<TextView android:textAppearance="#style/ClueText" android:id="#id/TextViewClue2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10.0px" android:text="" android:lines="2" />
</LinearLayout>
<LinearLayout android:gravity="top|center" android:orientation="vertical" android:id="#id/big_clue_container" android:paddingLeft="0.0px" android:paddingRight="0.0px" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">
<TextView android:textAppearance="#style/ClueTextBold" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10.0px" android:text="ACROSS" />
<LinearLayout android:gravity="top|center" android:orientation="vertical" android:id="#id/big_clue_across_container" android:background="#drawable/c_dialog_box" android:paddingTop="17.0px" android:paddingBottom="17.0px" android:layout_width="fill_parent" android:layout_height="200.0px">
<ListView android:scrollbarStyle="outsideOverlay" android:id="#id/big_clue_across_list" android:paddingLeft="5.0px" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
<TextView android:textAppearance="#style/ClueTextBold" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="10.0px" android:text="DOWN" />
<LinearLayout android:gravity="top|center" android:orientation="vertical" android:id="#id/big_clue_down_container" android:background="#drawable/c_dialog_box" android:paddingTop="17.0px" android:paddingBottom="17.0px" android:layout_width="fill_parent" android:layout_height="200.0px">
<ListView android:id="#id/big_clue_down_list" android:paddingLeft="5.0px" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView android:id="#id/ClueContainerArrow" android:background="#drawable/cross_down_arrow" android:layout_width="30.0px" android:layout_height="20.0px" android:layout_marginBottom="10.0px" android:layout_weight="1.0" />
</LinearLayout>
<LinearLayout android:gravity="bottom" android:layout_gravity="bottom|left|center" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<include android:id="#id/bottom_layout" android:layout_width="fill_parent" android:layout_height="160.0px" layout="#layout/bottom_layout" />
</LinearLayout>
<include android:id="#id/bottom_menu" android:layout_width="fill_parent" android:layout_height="fill_parent" layout="#layout/bottom_menu" />
</FrameLayout>
<LinearLayout android:gravity="center" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="50.0dip">
<LinearLayout android:gravity="center" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0">
<Button android:textAppearance="#style/ButtonText" android:textColor="#color/solid_white" android:id="#id/GameButton" android:background="#drawable/btn_footer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2.0dip" android:layout_marginRight="0.0dip" android:text="Game" android:layout_weight="1.0" />
<ImageView android:id="#id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#drawable/footer_line_divider" />
<Button android:textAppearance="#style/ButtonText" android:textColor="#color/solid_white" android:id="#id/LastWordButton" android:background="#drawable/btn_footer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="0.0dip" android:layout_marginRight="0.0dip" android:text="Prev Word" android:layout_weight="1.0" />
<ImageView android:id="#id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#drawable/footer_line_divider" />
<Button android:textAppearance="#style/ButtonText" android:textColor="#color/solid_white" android:id="#id/NextWordButton" android:background="#drawable/btn_footer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2.0dip" android:layout_marginRight="0.0dip" android:text="Next Word" android:layout_weight="1.0" />
<ImageView android:id="#id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#drawable/footer_line_divider" />
<Button android:textAppearance="#style/ButtonText" android:textColor="#color/solid_white" android:id="#id/KeyboardButtonHint" android:background="#drawable/btn_footer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="0.0dip" android:layout_marginRight="0.0dip" android:text="Hint" android:layout_weight="1.0" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

LinearLayout is not filling whole screen width

I have made a view for advertisements list and LinearLayout is not filling whole screen width, checked all the code and I don't understand where I am mistaken. Here is the code of my LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:id="#id/advertisement_list_container"
android:paddingTop="0.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="#id/advertisement_list_datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_margin_horizontal"
android:paddingTop="#dimen/small_listing_margin"
android:paddingRight="#dimen/activity_margin_horizontal"
android:paddingBottom="#dimen/small_listing_margin"
android:layout_marginBottom="#dimen/listing_margin"
android:text="#string/advertisement_list_datetime"
style="#style/TextWhiteNormalBoldGreyBackground" />
<LinearLayout
android:orientation="vertical"
android:paddingLeft="#dimen/activity_margin_horizontal"
android:paddingRight="#dimen/activity_margin_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#id/advertisement_list_from_city"
android:layout_marginLeft="#dimen/listing_margin"
android:text="#string/advertisement_list_from_city"
style="#style/TextNormalBold" />
<TextView
android:id="#id/advertisement_list_tire"
android:layout_marginLeft="#dimen/tire_margin"
android:text="#string/advertisement_list_tire"
style="#style/TextNormalBold" />
<TextView
android:id="#id/advertisement_list_to_city"
android:layout_marginLeft="#dimen/tire_margin"
android:text="#string/advertisement_list_to_city"
style="#style/TextNormalBold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_margin_vertical">
<ImageView
android:id="#id/advertisement_list_user_avatar"
android:layout_width="#dimen/avatar_result_size_width"
android:layout_height="#dimen/avatar_result_size_height"
android:src="#drawable/ic_default_avatar" />
<LinearLayout
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="#dimen/listing_margin"
android:layout_weight="1.0">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#id/advertisement_list_user_name"
android:text="#string/advertisement_list_user_name"
style="#style/TextDarkBlueNormalBold" />
<TextView
android:id="#id/advertisement_list_user_age"
android:text="#string/advertisement_list_user_age"
android:layout_marginLeft="#dimen/small"
style="#style/TextGreyNormal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="#dimen/text_normal"
android:layout_height="fill_parent"
android:layout_marginRight="#dimen/margin_small"
android:src="#drawable/ic_star_gold_no_border"
android:scaleType="fitCenter" />
<TextView
android:id="#id/advertisement_list_user_rating"
android:text="#string/advertisement_list_user_rating"
style="#style/TextNormalBold" />
<TextView
android:id="#id/advertisement_list_user_rate"
android:layout_marginLeft="#dimen/margin_micro"
android:text="#string/advertisement_list_user_rate"
style="#style/TextGreyNormal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="#dimen/text_normal"
android:layout_height="fill_parent"
android:layout_marginRight="#dimen/small"
android:src="#drawable/ic_car_blue"
android:scaleType="fitCenter" />
<TextView
android:id="#id/advertisement_list_user_car"
android:layout_marginRight="#dimen/small"
android:text="#string/advertisement_list_user_car"
style="#style/TextNormalBold" />
<TextView
android:id="#id/advertisement_list_user_car_y"
android:text="#string/advertisement_list_user_car_y"
style="#style/TextGreyNormal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="#dimen/text_normal"
android:layout_height="fill_parent"
android:layout_marginRight="#dimen/small"
android:tint="#color/text_dark_blue"
android:src="#drawable/ic_phone"
android:scaleType="fitCenter" />
<TextView
android:id="#id/advertisement_list_user_phone"
android:layout_marginRight="#dimen/small"
android:text="#string/advertisement_list_user_phone"
style="#style/TextNormalBold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_margin_vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="2.0">
<TextView
android:gravity="center_horizontal"
android:id="#id/advertisement_list_free_seats"
android:layout_width="fill_parent"
android:text="#string/advertisement_list_free_seats"
style="#style/TextDarkBlueMediumBold" />
<TextView
android:gravity="center_horizontal"
android:id="#id/advertisement_list_free_seats"
android:layout_width="fill_parent"
android:text="#string/advertisement_list_free_seats"
android:lines="2"
style="#style/TextDarkBlueSmall" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:background="#color/transparent"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="2.0">
<TextView
android:gravity="center_horizontal"
android:id="#id/advertisement_list_price"
android:layout_width="fill_parent"
android:text="#string/advertisement_list_price"
style="#style/TextDarkBlueMediumBold" />
<TextView
android:gravity="center_horizontal"
android:id="#id/advertisement_list_ride_price"
android:layout_width="fill_parent"
android:text="#string/advertisement_list_ride_price"
android:lines="2"
style="#style/TextDarkBlueSmall" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/divider"
android:contentDescription="#string/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
And this is the result what I see in my app: https://imgur.com/a/eKv1hHi
So advertisement must fill whole screen width.
Changed main LinearLayout to RelativeLayout and it fixed my issue!

Android Custom Checkbox selector issue

I have to customize a checkbox to show 2 different state while checked, i am using the following 2 images :
My custom selector is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/favourite_normal" android:state_checked="false"/>
<item android:drawable="#drawable/favourite_choose" android:state_checked="true"/>
<item android:drawable="#drawable/favourite_normal"/>
But thing is i am not getting proper result as in the image does not fills my checkbox view properly if i change the height and width of the checkbox which i have to do to adjust. The result i am getting like this:
The complete layout is given below :
<?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"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="74dp"
android:background="#drawable/bottom_bav_btn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:id="#+id/linearLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/jokeListViewBackButton"
android:src="#drawable/back_screen_button_normal"
android:layout_margin="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/linearLayout"
android:layout_toLeftOf="#+id/linearLayout2"
android:layout_toStartOf="#+id/linearLayout2"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/jokeTitleTextView"
android:gravity="center_vertical|center_horizontal"
android:textColor="#color/fontWhiteColor" />
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0/0"
android:id="#+id/jokeCountTxt"
android:gravity="center_vertical|center_horizontal"
android:textColor="#color/fontWhiteColor" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/linearLayout2"
android:gravity="center_vertical|center_horizontal">
<CheckBox
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/checkBox"
android:button="#drawable/custom_favourite_selector"
android:gravity="center_vertical|center_horizontal"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:weightSum="1"
android:background="#color/listViewBody"
android:layout_weight="0.71">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/scrollView" >
<com.gravityapps.framework.Utils.CustomTextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=""
android:id="#+id/jokeTextView"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textSize="25dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp" />
</ScrollView>
</LinearLayout>
<LinearLayout android:id="#+id/navbar"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/prevButtonLayout"
android:clickable="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView2"
android:background="#drawable/previous_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/randPrevButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView3"
android:background="#drawable/reverse_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/linearLayout5"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView4"
android:background="#drawable/copy_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/linearLayout6"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView7"
android:background="#drawable/share_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/randNextButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView5"
android:background="#drawable/forward_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/nextButtonLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView6"
android:background="#drawable/next_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am not sure why i am getting this result. Any help would be appreciated. Thanks
The size of Checkbox 40dp*40dp smaller than the image you defined in selector.
use wrap_content instead of static dimensions.
Depending on the previous answer, if you don't want your checkbox to be larger, than you will have to resize your images. I think these are your best options, either you wrap_content your checkbox width and height or you resize your image resources into smaller, ex. 40*40px

Complex android layout (overlapping, left/right align, center align)

I have to create the following layout on an Android device:
The requirements are as follows:
First layout which occupies the whole screen (fill_parent);
Second (at the bottom of the screen) overlays the first one and has the following formats:
3 columns;
occupies the whole screen width;
arrows are aligned left and right sides, and text area is resized based on screen width;
I've tried numerous things, but since I'm new to the Android world, I had no success yet.
Here is what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="100"
android:id="#+id/RootView">
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:id="#+id/mapImageView" />
<LinearLayout
android:id="#+id/bottomArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="#+id/adsArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageButton
android:src="#drawable/leftArrow"
android:id="#+id/btnPrev"
android:layout_alignParentRight="true"
android:layout_marginLeft="0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some summary text" />
</LinearLayout>
<ImageButton
android:src="#drawable/rightArrow"
android:layout_alignParentRight="true"
android:layout_marginRight="0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnNext" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
but the text doesn't seem to be center aligned, nor resized to the screen width:
Does someone has a clue?
Thanks.
Use this code for your required layout...
<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"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linear2" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<RelativeLayout
android:id="#+id/linear2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<ImageButton
android:id="#+id/leftButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/rightButton1"
android:layout_toRightOf="#+id/leftButton1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some summary text" />
</LinearLayout>
<ImageButton
android:id="#+id/rightButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
Please find the code below. Also, do not use multiple viewgroup for simple layout solution.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RootView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/mapImageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#android:drawable/ic_menu_gallery" />
<RelativeLayout
android:id="#+id/adsArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageButton
android:id="#+id/btnPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/leftArrow" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some summary text" />
</LinearLayout>
<ImageButton
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/rightArrow" />
</RelativeLayout>
</RelativeLayout>

Positioning ImageView

I need to positioning the ImageView at the same level of the user's name (vito in the example).
This is what I have:
And I want this (look at the second icon):
My xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingBottom="5px"
android:paddingTop="5px"
android:paddingLeft="5px"
android:orientation="horizontal"
style="#style/ListRow">
<ImageView
android:id="#+id/imagenItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:layout_gravity="top"
android:gravity="top"
android:layout_alignParentTop="true"
style="#style/iconLISTA" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/idUsuario"
android:textSize="#dimen/font_size_small"
android:textStyle="bold"
android:textColor="#color/list_item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<TextView
android:id="#+id/hora"
android:textSize="#dimen/font_size_small"
android:textStyle="bold"
android:textColor="#color/list_item_secondary_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="215px" />
</RelativeLayout>
<TextView
android:id="#+id/comentarios"
android:textSize="#dimen/font_size_small"
android:color="#color/list_item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0px" />
</LinearLayout>
</LinearLayout>
Thanks.
Change the ImageView and following LinearLayout hight attributes to both be wrap_content.
The ImageView is currently fill_parent which is making it take all available vertical space and centering it vertically.
Add:
android:scaleType="fitStart"
to the ImageView layout.
e.g.
<ImageView
android:id="#+id/imagenItem"
android:scaleType="fitStart"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:layout_gravity="top"
android:gravity="top"
android:layout_alignParentTop="true"
style="#style/iconLISTA" />
Try this, is bit simplified:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/imagenItem"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="top"
android:scaleType="fitCenter"
android:src="#drawable/avatar_default" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/idUsuario"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="usuario"
android:textStyle="bold" />
<TextView
android:id="#+id/hora"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="hora"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/comentarios"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="commmmment" />
</LinearLayout>
</LinearLayout>
And you shouldn't use px, use always dp/dip.

Categories

Resources