Android layout_weight iframe and scroll - java

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();

Related

How to prevent overlapping of buttons and other objects?

When i preview with android emulator, the layout preview is ok. But when I install the app in my mobile the views overlaps. It may be because of lack of space in the mobile screen but I have no idea. Please help me out. And also help me with making this app to work with all screen sizes. Thanks in advance.
First image is emulator preview 2nd is mobile preview
Here is the xml code :
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
android:background="#drawable/newbackground"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
app:srcCompat="#drawable/dicee_logo" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/dice1" />
<ImageView
android:id="#+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/dice2" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:background="#color/colorPrimary"
android:text="#string/button_text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/roll_button"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/roll_button"
android:layout_marginBottom="25dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
</RelativeLayout>
</LinearLayout>
This will keep the 2 textview to bottom and will expand in whatever view you use
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="#drawable/ic_word" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_word" />
<ImageView
android:id="#+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_pdf" />
</LinearLayout>
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:text="text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
</LinearLayout>
Try the below modified code. Since you want the buttons below each other. You cannot place one on right of other, so remove the alignRight.
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
**android:layout_marginTop="21dp"**
android:background="#color/colorPrimary"
android:text="#string/button_text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/roll_button"
android:layout_alignParentBottom="true"
**android:layout_alignRight="#+id/roll_button"**
android:layout_marginBottom="25dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />

Error when loading fragment from activity

I am new to android studio and am having some trouble with starting a fragment from an activity. I used code from on here to display the fragment and it was working up until now. I am using a third party library called 'DecoView' which needs to extend fragment, all the code is in 'LineDetails' (its too long to add all code). Does anyone recognise this error below?
Thank you in advance!
LINE DETAILS XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/fragment_place"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<com.hookedonplay.decoviewlib.DecoView
android:layout_width="250dp"
android:layout_height="200dp"
android:id="#+id/dynamicArcView"
android:layout_marginLeft="40dp"
android:layout_marginRight="8dp"
android:layout_marginTop="5dp">
</com.hookedonplay.decoviewlib.DecoView>
<EditText
android:id="#+id/actual"
android:inputType="number"
android:layout_width="150dp"
android:layout_height="46dp"
android:background="#drawable/border"
android:gravity="center"
android:hint="Enter Actual"
android:text=""
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="15sp"
android:layout_marginStart="26dp"
android:layout_alignBottom="#+id/textPercentage"
android:layout_alignStart="#+id/dynamicArcView" />
<Button
android:id="#+id/actual_btn"
android:layout_width="68dp"
android:layout_height="50dp"
android:background="#drawable/actualbutton"
android:shadowColor="#A8A8A8"
android:text="+"
android:textColor="#FFFFFF"
android:layout_above="#+id/textViewProgress"
android:layout_toEndOf="#+id/actual"
android:layout_marginLeft="12dp"/>
<TextView
android:id="#+id/textViewProgress"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginTop="15dp"
android:layout_below="#+id/actual"
android:layout_alignEnd="#+id/actual_btn"
android:layout_marginEnd="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:textSize="40sp"
android:id="#+id/textPercentage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
/>
<TextView
android:id="#+id/textViewLineType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="86dp"
android:text=""
android:textSize="40dp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#f15623"
android:layout_alignTop="#+id/dynamicArcView"
android:layout_toEndOf="#+id/dynamicArcView" />
<Button
android:id="#+id/buttonViewDetails"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#mipmap/info"
android:layout_marginLeft="250dp"
android:onClick="verifyButton"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp" />
</RelativeLayout>
</RelativeLayout>
<fragment
android:id="#+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
"xmlns:android="http://schemas.android.com/apk/res/android"
is missing
use below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="#+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Try adding
tools:context="com.yourpackagehere.FragmentThatIsInflatingTheXml">
to your first layout, the Relative one. Pls note that you have to change "yourpackagehere" with the name of your package and "FragmentThatIsInflatingTheXml" with the name of the actual Fragment
You said that DecoView extends a fragment so it should be added like this:
<fragment
android:id="#+id/fragment_id"
android:name="com.hookedonplay.decoviewlib.DecoView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

scroll view collapse nested relative layouts proplem

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.

Keyboard pushing edittext content when clicking

Keyboard pushing content of edittext up when I start writing something , already add android:windowSoftInputMode="adjustResize" in AndroidManifest. Please provide solution for this issue.
Here is my code.
<FrameLayout
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="com.example.mouad.fixmyphone.fragment.SendUsFragment"
android:background="#ffff">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#id/idtitle"
android:background="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail :"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#1A237E"
android:layout_marginTop="90sp"
android:id="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="SEND"
android:textStyle="bold"
android:layout_width="130sp"
android:layout_height="wrap_content"
android:id="#+id/sendbtn"
android:textColor="#ffffff"
android:background="#drawable/roundshapebtn"
android:layout_marginTop="17dp"
android:layout_below="#+id/msgtext"
android:layout_centerHorizontal="true" />
<EditText
android:background="#drawable/rounded_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your Problem in Short"
android:textStyle="bold"
android:id="#+id/msgtext"
android:maxLength="80"
android:maxLines="2"
android:inputType="textMultiLine"
android:layout_below="#+id/textmsgview"
android:layout_alignParentLeft="true"
android:drawableLeft="#drawable/ic_pb"
android:layout_alignParentStart="true"
android:drawablePadding="20dp"
android:paddingLeft="1dp"
android:paddingRight="12dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_marginTop="17dp"/>
<EditText
android:background="#drawable/rounded_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your E-mail . . ."
android:textStyle="bold"
android:id="#+id/emailtext"
android:inputType="textEmailAddress"
android:drawableLeft="#drawable/ic_email"
android:drawablePadding="20dp"
android:paddingLeft="1dp"
android:paddingRight="12dp"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tell us your problem :"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#1A237E"
android:layout_marginTop="20dp"
android:id="#+id/textmsgview"
android:layout_below="#+id/emailtext"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" />
</RelativeLayout>
it seems like you use adjust_resize for the keyboard, the view will be "resized" to fit your view(i mean layout)
if you dont want any resize, change to adjustPan
FYR Difference between adjustResize and adjustPan in android?
Problem solved with ScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Content here -->
</LinearLayout>
</ScrollView>
</LinearLayout>

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