I'm making a mistake somewhere while making a simple design - java

no matter what I do in my design, I want to center what I wrote with the photographs, but I cannot do the design, I wonder where I am going wrong I'm learning new and tried to make a design like in the photo
I'll create the rest using the recycler view and card view
Enough explanation, I hope I don't want to confuse you
<androidx.cardview.widget.CardView 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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView6"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Date" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView7"
android:layout_width="60dp"
android:layout_height="60dp"" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>

Splitted the center part to two linear layouts. Also added android:gravity="center|bottom" to the TextView which contains the date.
<androidx.cardview.widget.CardView 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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView6"
android:layout_width="60dp"
android:layout_height="60dp"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="text" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="text" />
</LinearLayout>
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|bottom"
android:text="Date" />
</LinearLayout>
<ImageView
android:id="#+id/imageView7"
android:layout_width="60dp"
android:layout_height="60dp" />
</LinearLayout> </androidx.cardview.widget.CardView>
Here's how it looks like. I added some colors so it's easier to see where layouts begin and end. The colors are not part of the xml.

Related

Android: How to get the Calendar in YEAR/MONTH/DATE Spinners

In my Android app, I am trying to get the birthday of the user. Below is my XML document .
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPurple"
app:popupTheme="#style/AppTheme.PopupOverlay"
style="#style/MyDrawerArrowToggle"
android:layout_marginTop="#dimen/toolbar_layout_top_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#+id/signUp_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_arrow_white" />
</LinearLayout>
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:text="#string/birthday"
android:textColor="#color/colorWhite"
android:gravity="center|left"
android:paddingLeft="20dp"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textStyle="bold"
android:text="#string/what_is_your_birthday"
android:gravity="center"
android:layout_marginTop="60dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp">
<DatePicker
android:layout_width="match_parent"
android:layout_height="150dp"
android:datePickerMode="spinner"
android:id="#+id/date_picker"/>
<!--<com.aigestudio.wheelpicker.widgets.WheelDayPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent" />-->
<!--<com.aigestudio.wheelpicker.widgets.WheelMonthPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
<!--<com.aigestudio.wheelpicker.widgets.WheelYearPicker-->
<!--android:layout_width="50dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_marginLeft="20dp"/>-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/colorPurple"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/signup_birthday_next_button_layout">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text = "#string/next_text"
android:textColor="#color/colorWhite"
android:textSize="14dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
This gives me the below UI
But I am looking for the below
How can I get the second UI?
Please add this xml file it may be help full to solve your problem.
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:gravity="center"
android:id="#+id/btnNotification"
android:text="What is your birthday"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<DatePicker
android:id="#+id/spinnerDatePicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:spinnersShown="true" />
<Button
android:text="next"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
You can use SpinnerDatePicker open source library it has UI like below
As it is open source you can change if you need.

My project has include page for every page. Include layout show well designed in include layout. But the owner page don't show same view

Every layouts in project has include layout. I have designed well in iclude layout. But in main layout of include layout don't show same view. for example the buttons move to the right of screen. I did different screen designs for small, normal, large and xlarge. But that didn't solve problem.
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/loginlayout"
android:layout_height="match_parent"
android:background="#drawable/login_arkaplan"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="90"
android:orientation="vertical"
>
<include layout="#layout/login_inner_part" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="10"
android:weightSum="2"
android:layout_gravity="center"
>
<TextView
android:id="#+id/textViewForgetPass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="#string/lostpass"
android:textColor="#color/colorOrange"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="#string/register"
android:textColor="#color/colorWhite"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
activity_login_inner_part.xml
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="20"
android:gravity="center"
android:background="#color/colorWhite"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="10"
android:gravity="center"
android:weightSum="3">
<ImageView
android:id="#+id/login_logo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
app:srcCompat="#drawable/login_logo"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:orientation="vertical">
<EditText
android:id="#+id/login_username"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:backgroundTint="#color/colorGrey"
android:ems="10"
android:hint="Eposta"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="267dp" />
<EditText
android:id="#+id/login_userpass"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:backgroundTint="#color/colorGrey"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="341dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/btn_login"
style="?android:attr/buttonStyleSmall"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="20dp"
android:background="#color/colorPrimary"
android:clickable="true"
android:focusable="true"
android:text="GÖNDER"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I don't know why this button move right of screen. I am doing this include layouts first time and I don't know reason of it. I can't solve it. Please help me.
Possible solution would be to use RelativeLayout to center the button with reference to it's parent instead of giving it a fixed left margin.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_login"
style="?android:attr/buttonStyleSmall"
android:layout_width="185dp"
android:layout_height="wrap_content"
<!-- IMPORTANT -->
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#color/colorPrimary"
android:clickable="true"
android:focusable="true"
android:text="GÖNDER"
android:textColor="#android:color/white" />
</RelativeLayout >

How to lay horizontaly these views?

I want to implement the following layout:
I did it as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginRight="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL"
android:textSize="14sp"
android:layout_marginBottom="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:padding="10dp"
android:text="Text Box 1"
android:textSize="14sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL 2"
android:layout_marginBottom="5dp"
android:textSize="14sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="BLA-1"
android:background="#color/white"
android:textSize="14sp"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center|bottom"
android:text="and"
android:textSize="14sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="BLA-2"
android:background="#color/white"
android:textSize="14sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Basically I used LinearLayouts and gravity.
It works but it seems kind of complex and I noticed that when I increase the margins left and right of the and text the texts BLA-1 and BLA-2 get cut off.
Is there a better way for this?
I think I can not use a relative layout as I would not be able to have the views take these sizes across the screen, right?
UPDATE:
Also with my approach any kind of padding in the TextViews cuts off the text
This looks the same as on screenshot (just customize colors)
<?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="horizontal"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="Text Box 1"
android:padding="4dp"
android:textColorHint="#757575" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="BLA-1"
android:padding="4dp"
android:textColorHint="#757575" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:text="and" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"
android:hint="BLA-2"
android:padding="4dp"
android:textColorHint="#757575" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I think LinearLayout is a good choise even though it is complex if you want to keep the weights.
You should change all your TextViews to wrap_content so they won't get cut off.
If you still want to avoid spaces you can wrap each TextView with a LinearLayout or FrameLayout like this:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LABEL2" />
</LinearLayout>
Here you can get it using Linear Layout. Have a look at below xml layout exactly what you are looking for.
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="3"
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:id="#+id/llOne"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="LABEL"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="textbox1"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/llTwo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="LABEL"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="BLA1"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0.3"
android:text="and"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/llThree"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_weight="0.6"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:hint="BLA2"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Android studio XML textview on an imageview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="#string/image_description" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
I have a question i cant get the text on my imageview, i think its something with the layers. Please help me..
im btw a beginner in Android studio XD
you are using LinearLayout which stacks your view one by one, either in horizontal direction or vertical direction (Orientation).
So use RelativeLayout instead if you want views overlapping.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="#string/image_description" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
</RelativeLayout>
Change your Linear Layout to Relative layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="#string/image_description" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
</RelativeLayout>
**Well You are better to use framelayout **. I hope this will help you
its not good way. better print something with java like:
LinearLayout lView = new LinearLayout(this);
myText = new TextView(this);
myText.setText("My Text");
lView.addView(myText);
setContentView(lView);
This works.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="hii" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="yo"
android:textColor="#color/bg_login"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>
</RelativeLayout>
</LinearLayout>
This code put the text in the middle of the image as you've requested for.
<?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:id="#+id/nations"
android:background="#color/colorPrimary"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_launcher"
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:contentDescription="image" />
<TextView
android:id="#+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="#string/list_number_placeholder"
android:textColor="#color/bar_separator_color"
android:textSize="50dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/></RelativeLayout>
</LinearLayout>
Try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/picture"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/text"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My super text"
android:textColor="#android:color/white"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:textSize="48sp" />
<LinearLayout
android:id="#+id/controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#7f000000"
android:orientation="vertical"
android:layout_gravity="bottom"/>
</FrameLayout>

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