scroll view collapse nested relative layouts proplem - java

i have this xml :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical"
android:padding="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/layout_comands"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layoutDirection="ltr">
<TextView
android:id="#+id/textView_hfccomands"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:text="text " />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/textView_hfccomands"
app:srcCompat="#drawable/ic_business_index" />
<TextView
android:id="#+id/textView_hfc_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/textView_hfccomands"
android:layout_toLeftOf="#id/imageView"
android:layoutDirection="rtl"
android:text="text " />
</RelativeLayout>
<View
android:id="#+id/seprator1"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="#id/layout_comands"
android:layout_marginTop="#dimen/main_screen_bottom_margings"
android:background="#color/light_blue" />
<RelativeLayout
android:id="#+id/layout_lvExpMissions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/seprator1"
android:layout_marginTop="#dimen/main_screen_bottom_margings"
android:background="#color/white">
<ExpandableListView
android:id="#+id/lvExphfc_my_missions"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<View
android:id="#+id/seprator2"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="#id/layout_lvExpMissions"
android:background="#color/light_blue"></View>
<RelativeLayout
android:id="#+id/layout_button_help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/seprator2"
android:layout_marginTop="#dimen/main_screen_bottom_margings">
<Button
android:id="#+id/button_help"
style="#style/button_custmoized"
android:layout_width="match_parent"
android:layout_height="60dp" />
</RelativeLayout>
<View
android:id="#+id/seprator3"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="#id/layout_button_help"
android:layout_marginTop="#dimen/main_screen_bottom_margings"
android:background="#color/light_blue"></View>
<RelativeLayout
android:id="#+id/layot_emergency_reports"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/seprator3"
android:layout_marginTop="#dimen/main_screen_bottom_margings"
android:background="#color/white">
<ListView
android:id="#+id/listView_emergencyReports"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<View
android:id="#+id/seprator4"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_below="#id/layot_emergency_reports"
android:layout_marginTop="#dimen/main_screen_bottom_margings"
android:background="#color/light_blue"></View>
</RelativeLayout>
the proplem is my scroll view some way wrap the content and act wierd !
i just want to be able to scroll the whole content down
but the scroll view push the relative layut to the top of the screen!
what did i miss here

add this code to your relative layout in xml
android:focusableInTouchMode="true"
android:visibility="visible"
try this

Add this property to ScrollView in xml
android:fillViewport="true"
it will solve the issue.

Related

Android layout_weight iframe and scroll

sorry for my poor english in advance
I have a design problem on android studio.
I used multiples devices (From version 8 to 10) and it works fine, and one device (version 6) which has a different output (you can check my screens below)wrong display click here
good display click here
unfortunately i don't know why it goes wrong, it might be a problem with layout_weight, in my code i use a Frame layout to switch out between differents Views, it looks like the Framelayout doesn't take any height (i want it to take the available space)
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/choose_model"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Spinner
android:id="#+id/select_your_model"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/text_model_title"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/text_model_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:text="#string/choose_mod"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Spinner_model_preference_text"
android:layout_width="160dp"
android:layout_height="26dp"
android:layout_alignTop="#+id/select_your_model"
android:layout_alignParentEnd="true"
android:layout_marginEnd="45dp"
android:gravity="center"
android:textColor="#android:color/darker_gray"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA">
<FrameLayout
android:id="#+id/Frame_layout_preferences_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0">
<Button
android:id="#+id/save_user_preferences"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/save" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_preferences_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/recycler_view_preferences_model"
android:layout_alignParentStart="true"
android:background="?android:attr/listDivider" />
</RelativeLayout></LinearLayout>
You have the problem, because you have a FrameLayout inside a fragment. I recommend the next
If you only want to have a view and it has different content, you can have a activity
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Spinner
android:id="#+id/select_your_model"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/text_model_title"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/text_model_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:text="#string/choose_mod"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Spinner_model_preference_text"
android:layout_width="160dp"
android:layout_height="26dp"
android:layout_alignTop="#+id/select_your_model"
android:layout_alignParentEnd="true"
android:layout_marginEnd="45dp"
android:gravity="center"
android:textColor="#android:color/darker_gray"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA">
<FrameLayout
android:id="#+id/Frame_layout_preferences_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0">
<Button
android:id="#+id/save_user_preferences"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/save" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_preferences_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/recycler_view_preferences_model"
android:layout_alignParentStart="true"
android:background="?android:attr/listDivider" />
</RelativeLayout></LinearLayout>
Replace the FrameLayout with an imageview
if you want to have fragments. i recommend the next
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Call the fragment in activity
getSupportFragmentManager().beginTransaction()
.replace(R.id.main_container, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();

Adjust pan issue in android keyboard

So basically i want to push the bottom button to top of the keyboard and push the other content up after opening the keyboard.
The problem is that if i use adjust pan the button overlap with the edit text and if i use the adjust resize button won't come up.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical"
tools:context="com.lifeincontrol.activities.home.AddCompanionActivity"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:background="?attr/colorPrimary"
android:titleTextColor="#android:color/white"
app:popupTheme="#style/AppTheme.PopupOverlay"
>
</android.support.v7.widget.Toolbar>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/companion_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:src="#drawable/ic_add_companion_illustration"
/>
<LinearLayout
android:id="#+id/number_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/companion_image"
android:layout_marginLeft="15dp"
android:layout_marginTop="62dp"
android:orientation="horizontal"
>
<LinearLayout
android:id="#+id/country_code_layout_before"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="7dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/text_country_code_before"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginRight="12dp"
android:drawableRight="#drawable/arrow_drop_down"
android:src="#drawable/flag_in"
/>
<ImageView
android:id="#+id/drop_down_before"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="12dp"
android:paddingTop="12dp"
android:src="#drawable/down_arrow_logging"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginRight="12dp"
android:layout_marginTop="4dp"
android:background="#5E000000"
/>
</LinearLayout>
<EditText
android:id="#+id/number_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:hint="Phone Number"
android:inputType="number"
android:maxLines="1"
android:textColorHint="#aaa"
/>
<ImageView
android:id="#+id/phone_book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="11dp"
android:src="#drawable/circle"
android:visibility="gone"
/>
</LinearLayout>
<EditText
android:id="#+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/number_field"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="30dp"
android:hint="Name"
android:imeActionLabel="Done"
android:imeOptions="actionDone"
android:maxLines="1"
android:singleLine="true"
android:textColorHint="#aaa"
/>
<View
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_below="#+id/name_edit_text"
/>
<Button
android:id="#+id/button_send"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:background="#color/companion_button_send"
android:text="Send"
android:textColor="#color/white"
android:textSize="14sp"
/>
</RelativeLayout>
</ScrollView>
</LinearLayout>
first image before keyboard open
second image here i want to show the green button on top of keyboard
Add the below line to your activity java file
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
And then add a ScrollView to the layout. Remember ScrollView can hold only 1 child view.
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<--------Your content---------->
</RelativeLayout>
</ScrollView>
1.change adjustpan to adjustResize in your menifest file like below
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"/>
put your xml code inside scrollView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<--------Your content---------->
</RelativeLayout>
</ScrollView>

Issue with listview scrollable

i don't know why my list view doesn't scroll completely.
I show you also single list view item.XML about adapter's xml where i put the item for every rows of my listview, so i hope that you can help me!
Thanks everybody!
I show you pic!
https://i.stack.imgur.com/8ub2W.png
this is .xml
<?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="match_parent"
android:id="#+id/a"
android:layout_marginLeft="5dp"
android:background="#color/white"
>
<ListView
android:id="#+id/listview"
android:layout_marginTop="0dp"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
single_listview_item.XML
<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:padding="8dp"
>
<CheckBox
android:id="#+id/chk_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<ImageView
android:id="#+id/ivImage"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_toRightOf="#id/chk_box"
android:layout_toLeftOf="#id/ivImage"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/chk_box"
android:textStyle="bold"
android:textColor="#000000"
android:text="This ia name"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/caratteristica"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:layout_toRightOf="#id/chk_box"
android:textStyle="italic"
android:text="This is caratteristica"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"
android:text="10"/>
<TextView
android:id="#+id/valuta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textSize="12sp"
android:textStyle="italic"
android:text="$"/>
</LinearLayout>
<Spinner
android:id="#+id/simpleSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:entries="#array/country_arrays"
android:visibility="visible"/>
<NumberPicker
android:id="#+id/np"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"/>
</LinearLayout>
</RelativeLayout>
In your adapter's xml , RelativeLayout tag ,write wrap_content replace of match_parent like below;
android:layout_height="wrap_content"
Change your single_listview_item.XML's RelativeLayout from android:layout_height="match_parent" to android:layout_height="wrap_content"
Change your ListView's height to wrap_content too

In a relative layout how can I make the last element adjust to the increase of data in the preceding elements?

I have a layout as follows. The problem I have is that if the TextView of friend_name is very long it “pushes” down the rest and they overlap/cover last ViewStub of friend_last_msg
How can I make the last ViewStub to also “adjust” on this “lowering of the other widgets?
Or else how could I make that last view stub to be inside the LinearLayout and displayed to the left side and down?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:id="#+id/friend_img”
android:layout_width="#dimen/friend_big”
android:layout_height="#dimen/friend_big”
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
>
<TextView
android:id="#+id/friend_name”
android:layout_toRightOf="#id/friend_img"
android:layout_marginBottom="#dimen/layout_small_padding"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:ellipsize="end"
android:gravity="top"
/>
<ViewStub
android:id="#+id/friend_sign”
android:inflatedId="#+id/friend_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/friend_sign_layout”/>
<TextView
android:id="#+id/friend_contact”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:padding="5dp"
/>
</LinearLayout>
<ViewStub
android:id="#+id/friend_last_msg”
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout="#layout/friend_last_msg"/>
</RelativeLayout>
First of all enter the closing commas right like this then enter the android:layout_height and android:layout_width values according to your needs.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<ImageView
android:id="#+id/friend_img[**"**]
android:layout_width="#dimen/friend_big[**"**]
android:layout_height="#dimen/friend_big"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
>
<TextView
android:id="#+id/friend_name[**"**]
android:layout_toRightOf="#id/friend_img"
android:layout_marginBottom="#dimen/layout_small_padding"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:ellipsize="end"
android:gravity="top"
/>
<ViewStub
android:id="#+id/friend_sign"
android:inflatedId="#+id/friend_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="#layout/friend_sign_layout"/>
<TextView
android:id="#+id/friend_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:padding="5dp"
/>
</LinearLayout>
<ViewStub
android:id="#+id/friend_last_msg"
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout="#layout/friend_last_msg"/>
You can to use this way:
Add an id -> #+id/container to parent
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#+id/friend_img"
android:orientation="vertical">
For your stub layout just change to this:
<ViewStub
android:id="#+id/friend_last_msg"
android:inflatedId="#+id/friend_last_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/container"
android:layout_toRightOf="#+id/friend_img"
android:layout_alignParentRight="true"
android:layout="#layout/friend_last_msg"/>

Android layout inconsistency

I have a layout that is being displayed in two different layouts. First one is being displayed in a LinearLayout and it behaves as expected:
However, when this layout is part of a listview, the textview is not centered:
Here's the layout:
<?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="130dp"
android:orientation="vertical">
<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="100dp"
android:orientation="horizontal"
android:padding="5dp">
<com.parse.ParseImageView
android:id="#+id/iv"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"/>
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.5"
android:layout_marginLeft="10dp"
android:textAppearance="#android:style/TextAppearance.Holo.Medium"
android:ellipsize="end"
android:maxLines="3"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:orientation="horizontal"
android:paddingLeft="10dp">
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/blue"
android:layout_gravity="center"
/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_source"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="#android:style/TextAppearance.Holo.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/gray"
android:layout_margin="7dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fire"
android:layout_gravity="center"/>
<TextView
android:id="#+id/tv_viewCount"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-light"
android:textAppearance="#android:style/TextAppearance.Small"
android:gravity="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="5dp"/>
</LinearLayout>
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="#color/white"
android:layout_alignTop="#+id/pin"
android:layout_alignBottom="#+id/pin"
android:layout_alignLeft="#id/pin"
android:layout_alignRight="#+id/pin"
android:gravity="center"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
The textView that I am referring to is at the bottom with id comment_tv
What am I doing wrong?
Thanks
Your pin+text inside a relative layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="center_vertical" >
<ImageView
android:id="#+id/pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_pin"/>
<TextView
android:id="#+id/comment_tv"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#id/pin"
android:gravity="center"
android:layout_marginTop="10dp" //set this higher if you need
android:layout_centerHorizontal="true" //if this text will be not in the center
//you can use the "layout_marginLeft" to put whatever you want
/>
</RelativeLayout>
This should but the text on the spot you want
I tried it with your image and this is my result with underlying code. Is this what you are looking for?
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sample"
android:gravity="center"
android:text="12"
android:textSize="18sp" />
</LinearLayout>
And heres a snapshot of this code:

Categories