My rotated TextView is cut off. What i have to do? - android

This is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!--left-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="#color/nero"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Nothing important"
android:textSize="40dp"/>
</LinearLayout>
<!--right yellow column-->
<LinearLayout
android:id="#+id/layout_barra_nord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6"
android:background="#color/giallo"
android:orientation="vertical">
<TextView
android:paddingTop="20dp"
android:background="#android:color/background_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation="90"
android:singleLine="true"
android:gravity="center"
android:layout_gravity="bottom"
android:textColor="#color/nero"
android:textSize="30sp"
android:textStyle="bold"
android:text="try"
/>
<!--android:text="long text"-->
</LinearLayout>
</LinearLayout>
</LinearLayout>
i'd like to have this effect for every text:
but if I try to add a longer text, my text will be cut off:
I see that lot of people have this problem, but I haven't found anything helpful.
How to fix this problem?

Your TextView width is match_parent which means your TextView will have the same width as your parent LinearLayout. Your LinearLayout have a narrow width so your TextView will have a narrow width too.
EDIT: You have to think of your TextView as if he is on the same orientation as your parent. If he had the same orientation you would have the TextView with a narrow width.

Change the following attribute of TextView
android:layout_height="wrap_content"
to
android:layout_height="match_parent"
so that it stretch down to the full parent height.

Related

Cannot see textview

I am trying to make a layout with this 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:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
>
<android.support.v7.widget.CardView
app:cardCornerRadius="#dimen/cardview_corner_radius"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#f27181"
android:id="#+id/charity_overview_card"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.sharesmile.share.views.LBTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#color/white"
android:padding="9dp"
android:text="Women Empowerment"
android:id="#+id/iv_charity_category_title"
/>
<ImageView
android:background="#color/colorPrimaryDark"
android:layout_width="128dp"
android:layout_height="126dp"
android:id="#+id/iv_charity_overview"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.sharesmile.share.views.LBTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_charity_amount"
android:textColor="#color/black"
android:textSize="15sp"
android:text="Test"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
but the last textview is not visible, even in the preview it is not showing, it shows like this :
As you can see the textview is not visible, i haven't given any weight, still facing this issue.
Also when i increase the size of the textview the value is visible as you can see here :
LinearLayout inside other parent LinearLayout with dynamic size will produce this type of issues. You should avoid nesting layout inside layout as much as possibile.
This issue can be simply fixed by removing the parent layout orientation.
For improvement
<CardView>
<LinearLayout> vertical
//Add 'N' child items here
</LinearLayout>
</CardView>
Change the following properties of your main LinearLayout, Make height and width to match_parent
android:layout_width="match_parent"
android:layout_height="match_parent"

android textview layout weight issue

I am working on a project. I am required to make a TextView to be fit into 1 line (as shown below).
But after I tried adjusting layout_weight, it fails.
Here is my code (with original layout_weight):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tool="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/view_toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="25dp">
(omitted)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/padding_small"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:textAppearance="?android:attr/textAppearanceListItemSmall">
<TextView
android:id="#+id/hose_expired_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/padding_x_larger"
android:layout_weight="1"
android:textColor="#color/textColor_dark"
android:textSize="#dimen/font_size_medium" />
<TextView
android:id="#+id/hose_expired_count_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/padding_larger"
android:layout_weight=".5"
android:textColor="#color/textColor_dark"
android:textSize="#dimen/font_size_medium" />
</LinearLayout>
(omitted)
</LinearLayout>
(omitted)
</LinearLayout>
</RelativeLayout>
How can I fix the layout_weight (and possibly width, height, etc.) so that I can get the TextView fitted?
How about you don't use weights for the hose_expired_count_amount TextVIew. Just use wrap_content for the width and don't add any weight. Your "Hose Expired" text will fill the space.
<TextView
android:id="#+id/hose_expired_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/padding_x_larger"
android:layout_weight="1"
android:textColor="#color/textColor_dark"
android:textSize="#dimen/font_size_medium" />
<TextView
android:id="#+id/hose_expired_count_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/padding_larger"
android:textColor="#color/textColor_dark"
android:textSize="#dimen/font_size_medium" />
</LinearLayout>
If you want the text to be directly beside each other, you'd need to right-align your hose_expired_count TextView by setting the gravity as right/end
Just use wrap_content for width of hose_expired_count_amount

Android Scrollview content size smaller when should be

I want to have a "fixed_space" at the top of screen and a "scrollview" at the bottom of the screen which should be below fixed_space. The rest of the screen is a container "rest_space".
Unfortunately my scrollview has a shorter height(by 100dp which fixed_space has) ,if content is too big/scrollable.
I tried to achieve same with ConstraintLayout and RelativeLayout, but I have got same result.
Any ideas why scrollview has 100dp shorter height, as it should be?
EDIT: Scrollview should take as much space as she needs.
<?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">
<View
android:id="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_red_dark" />
<View
android:id="#+id/rest_space"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:color/black" />
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_dark"
android:fillViewport="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" />
</ScrollView>
</LinearLayout>
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_red_dark" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/rest_space"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/scrollview"
android:background="#android:color/black" />
<ScrollView
android:id="#+id/scrollview"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_dark"
android:fillViewport="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" />
</ScrollView>
</RelativeLayout>
</LinearLayout>
Ok, I think this should solve your probem:
First, I started by using RelativeLayout. I did it in order to get the fixed_space aligned to the top and the scrollview aligned to the bottom.
Then I changed the View for a LinearLayout and put a TextView within it so I could use wrap_content and this is the tricky part:
When you use ScrollView with wrap_content and a View with the weight stuff, Android can't make the calculations it needs to get the screen drawed because there is no reference. When I put the TextView with wrap_content itself that gives the reference because Android know the size of the text.
You don't have to use the TextView but you will need anything that gives Android that reference.
In this case, the scrollview is going to be stretched, not the LinearLayout. If you want the second to get strached, then I'm afraid you are going to need to set a fixed height to your scrollview.
<?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="match_parent"
android:orientation="vertical">
<View
android:id="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:background="#android:color/holo_red_dark" />
<LinearLayout
android:id="#+id/rest_space"
android:layout_below="#+id/fixed_space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black">
<TextView
android:text="Test"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollview"
android:layout_below="#id/rest_space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_dark"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMIDDLE OF SCROLLVIEW \n\n\n\n\n\n\n\n\n\n\n\nEND OF SCROLLVIEW" />
</ScrollView>
</RelativeLayout>

Make an Imageview assume the biggest width allowed by its parent

I want an Imageview to expand and assume the biggest width respecting the parent viewgroups margins. The width of the parent must however behave like wrap_content when the ImageView is dynamically hidden.
Consider the following layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="#drawable/strasse_hintergrund"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Text"/>
</LinearLayout>
The following images show what the layout looks like, both with a short and a long text in the textview:
I need the ImageView to always have assume width as in the second version (with the long text).
What is the best way to achieve this?
Try this :
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/strasse_hintergrund"/>
and maybe change :
android:layout_width="match_parent"
to
android:layout_width="wrap_content"
EDIT :
Here is my 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"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="19dp"
android:background="#color/dark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_weight="0.02">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="7pt"
android:textColor="#color/white"/>
</android.support.v7.widget.Toolbar>
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
/>
<TextView
android:id="#+id/textView"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10pt"/>
</LinearLayout>
Result :
Place TextView and ImageView in different LinearLayouts and place both inside a third LinearLayout OR
use match_parent instead of wrap_content for your TextView width
You can set this android:scaleType="fitXY" property for Imageview
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/your_image"/>

set TextView in HorizontalScrollView to the right

I have a simple construction; a TextView in a Scrollview, but I cannot make it work as I want.
The problems I get now;
The ScrollView keeps expanded when once the TextView was larger than the width of the screen, even when I set the text of TextView to nothing.
The TextView is on the left side.
I got the following:
<HorizontalScrollView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="right"
android:background="#drawable/background_scrollviews_display"
android:id="#+id/scrollViewSum">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right">
<TextView
style="#style/TextStyleDisplay"
android:textSize="#dimen/fontSizeTextViewSum"
android:paddingLeft="#dimen/paddingDisplayTextViews"
android:paddingRight="#dimen/paddingDisplayTextViews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="right|center"
android:id="#+id/textViewSum"/>
</LinearLayout>
</HorizontalScrollView>
What I want;
The TextView on the right;
The ScrollView only expand when the TextView is larger than width of the screen;
I tried a lot, but I simply cannot find the right solution.
I hope someone can help me out!
I have a two clue to solve your problems:
1) make LinearLayout orientation Vertical, then you can position TextView on the right
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right">
<TextView
style="#style/TextStyleDisplay"
android:textSize="#dimen/fontSizeTextViewSum"
android:paddingLeft="#dimen/paddingDisplayTextViews"
android:paddingRight="#dimen/paddingDisplayTextViews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="right|center"
android:id="#+id/textViewSum"/>
</LinearLayout>
2) make TextView wrap_content instead of match_parent
<TextView
style="#style/TextStyleDisplay"
android:textSize="#dimen/fontSizeTextViewSum"
android:paddingLeft="#dimen/paddingDisplayTextViews"
android:paddingRight="#dimen/paddingDisplayTextViews"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="right|center"
android:id="#+id/textViewSum"/>
make the textview width wrap_content
I have hard coded stuff like padding and text size etc. as I did't have your dimensions, you can change it later as per your requirements.
check if following code snipet helps.
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollViewSum"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewSum"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right|center"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="ldksjfkdlfkfldksjfkdlfkf"
android:textSize="20sp" />
</LinearLayout>
</HorizontalScrollView>

Categories

Resources