I wanted 2 textviews on my listview that I want to one of them has right align and another align center but all of them aligend left !!! my listview 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:background="#ffffff"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/tv_subject"
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_pic"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:contentDescription="ads"/>
<TextView
android:layout_gravity="right"
android:gravity="right"
android:textColor="#ffffff"
android:paddingRight="5dp"
android:layout_weight="0.5"
android:id="#+id/tv_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
this code worked successfully but when compiler build the application and I want to touch one row at list view in fact when my finger is at list view color of row should be change, but because I had to set width match_parent it cover the entire screen.
how can I make this the output that I want and when my finger is on the selected row user see the color of the row has changed.
Just delete android:background="#ffffff". If you want change color - set it to ListView.
Related
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true">
<ListView
android:id="#+id/attackslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff" />
</HorizontalScrollView>
I put a ListView inside an HorizontalScrollView because its content is way too long to fit in the screen, but what i get is that the list looks like this (the background color is there to show where the list's childs stop)
while i want all the childs equally spaced in there until the end of the list, which i get if the ListView is not inside a scrollbar
My custom layout I use in the adapter looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent">
<TextView
android:id="#+id/Moves"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_weight="1"
android:gravity="center"
android:text="Moves"
android:textSize="14dp" />
<TextView
android:id="#+id/Hitboxactive"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_weight="1"
android:gravity="center"
android:text="Hitbox Active"
android:textSize="14dp" />
</LinearLayout>
How should I handle this situation? Can I change the values during runtime?
Should I use a different View?
Thanks
I am trying to create a screen where you have a ScrollView on top and under that you have a TextView and a Button.
The ScrollView contains a TableLayout which it self contains TextView's, Button's and EditText's.
What I would like to achieve is that when a EditText is focues and the input panel opens on the phone, the buttom footer would be moved on top of the panel and the scroll area resized smaller, so that you can click the calculate button at any moment.
Here is my current xml:
The activity:
<?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">
<include layout="#layout/activity_germinative_scroll"/>
<TextView
android:id="#+id/textViewCalculationResult"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".70"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="0.00 KG/HA"
android:textSize="35sp"/>
<Button
android:id="#+id/calculateGerminative"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".30"
android:text="#string/calculate_germinative"
android:textSize="25sp"
android:textAllCaps="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/menu_button_states"
android:nextFocusDown="#id/editSeedMass"/>
</LinearLayout>
Scroll activity:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:showDividers="beginning|end"
>
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="10dip"
>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:id="#+id/teraMass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".40"
android:textSize="20sp"
android:editable="false"
android:text="#string/seed_mass_text"
android:textAllCaps="true"/>
<Space
android:layout_width="13dp"/>
<Button
android:id="#+id/seedMassInfo"
android:tag="seedMassInfo"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/info"/>
</TableRow>
<Space
android:layout_height="3dp"/>
... Many other TableRow's with the exact same layout...
</TableLayout>
</ScrollView>
So what happens right now is that when I focus on one of the input fields in my scroll area, the button at the bottom gets resized into a very thin little button and depending of the screen size, the text-field in the footer will get resized also.
I use this setting for the activity in the manifest:
android:windowSoftInputMode="stateHidden|adjustResize">
Is the problem because of the overall layout I use or what?
You should set fixed height for the Button calculateGerminative and TextView textViewCalculationResult, and set the scrollview height to dynamic, i.e.
android:layout_height="0dp"
android:layout_weight="1"
I have a custom array adapter where each item consists of two textviews over an imageview(SmartImageView is a third party imageview that renders remote images from a url):
<?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">
<com.loopj.android.image.SmartImageView
android:id="#+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Data Model Title"
android:textSize="30sp" />
<TextView
android:id="#+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Data Model Details"
android:textSize="15sp" />
</RelativeLayout>
</FrameLayout>
I see the image with a top and bottom margin and no text:
1) the RelativeLayout with the text should go over the image since it is the 2nd child of FrameLayout
2) why is there a margin above and below my image? I said my imageview's dimensions were match parent, and didnt specify any top or bottom margins for it
It should and it actually does. The text didn't show up for a different reason.
I added android:scaleType="centerCrop" which filled the row completely.
I want to make horizontal gallery to perform custom views:
for example a want to have an array of products with its' description, price and photo,
I build custom layout and override getView and adapter.
Description text can be too large and I return only small portion of it and load to the view. There is a button "more" to expand this view. Below the gallery there is an another layout view with some buttons, controls etc.
OnMoreButtonClick I only set full text to the description TextView. Gallery height I wrapcontent and I think it has to change size dynamically.
BTW if I load the full text without short one - everything is ok.
This is main screen of app, when I press button I want gallery item to stretch down and pull TimeAndDatePicker down.
But when I press it I can only see:
And if I load the full text without small one everything is ok:
Main.xml:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="fill_parent"
android:id = "#+id/scene"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/main_background" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ru.human.samples.CustomGallery
android:id="#+id/galleryUnique"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:spacing="1dp" android:unselectedAlpha="255.0" android:visibility="visible" android:fadingEdge="none"/>
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
And galleryItem xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
style="#style/PriceText"
android:text="Medium Text"/>
</LinearLayout>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
style="#style/BodyText"
android:text="TextView" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
style="#style/BodyText"
android:text="Medium Text"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
There is one "hack" in my case.
I put gallery in one more LinearLayout, make it WrapContent by default and Gallery FitParent,
when i click "more" button i expand the Layout height (previous height + countlines of new textview * sizeoftext).
I have a ListView which uses a custom adapter to display rows of data. Each row contains two TextViews; one is left-justified and one is right-justified.
Ideally what I want is for each TextView to take up at most half of the width of the row. I've accomplished this using the following row xml layout:
<?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" >
<TextView
android:id="#+id/description"
style="#style/ProductSpecNameFont"
android:layout_width="fill_parent"
android:layout_gravity="left"
android:layout_weight="1"
android:padding="#dimen/margin_sides"
android:text="Display Size" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/value"
style="#style/ProductSpecValueFont"
android:layout_alignParentRight="true"
android:padding="#dimen/margin_sides"
android:text="3.5 Inches" />
</RelativeLayout>
This "almost" works perfectly. The problem is that the rows which contain text on the right-side TextView that takes up multiple lines are not right-justified. The single-line rows are right-justified as I would like. Here is a screenshot of what I'm talking about:
Why aren't the multiple-line TextViews right-justified, and how can I make them so?
Try setting the gravity of the TextView. It looks like what's happening is the TextView is aligned to the right, but the text itself is left justified.
android:gravity="right"
Try using android:weightSum on your LinearLayout. Like 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:weightSum="1.0">
<TextView
android:id="#+id/description"
style="#style/ProductSpecNameFont"
android:layout_width="fill_parent"
android:layout_gravity="left"
android:layout_weight="0.5"
android:padding="#dimen/margin_sides"
android:text="Display Size" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5" >
<TextView
android:id="#+id/value"
style="#style/ProductSpecValueFont"
android:layout_alignParentRight="true"
android:padding="#dimen/margin_sides"
android:text="3.5 Inches" />
</RelativeLayout>