I have this code:
<LinearLayout
android:layout_weight="0.5"
android:layout_width="0px"
android:id="#+id/linearLayout2"
android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout
android:layout_weight="0.45"
android:layout_width="fill_parent"
android:id="#+id/linearLayoutMainLogo"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="0px">
<ImageView
android:src="#drawable/logo"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:id="#+id/imageViewLogo"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
I need to set ImageView in center of LinearLayout by horizontal and by vertical simultaneously, but my code doesn't work. Where did I do mistake? Thank you
This is wrong i think:
android:layout_width="0px"
android:layout_height="0px"
Just correct with this:
<LinearLayout
android:layout_width="fill_parent"
android:id="#+id/linearLayout2"
android:orientation="vertical"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_weight="0.45"
android:layout_width="fill_parent"
android:id="#+id/linearLayoutMainLogo"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/icon"
android:gravity="center"
android:layout_width="wrap_content"
android:id="#+id/imageViewLogo"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Related
I'm making a fragment with a horizontal scroll on the previous screen.
the HorizontalScrollView is in a fragment
it worked fine when it was an activity but when you change it to a fragment the interface gets stuck
I have a HorizontalScrollView inside my ViewPager.
but when putting it in a fragment the interface does not work as it should, but at the moment of moving the view to the right or left it remains as the image
Like shown in Image below.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/FragmentoLayout_fonemasTar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView
android:id="#+id/horizontalScrollView1Tar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/secondary_text_light"
android:fadeScrollbars="false"
android:scrollbarSize="2dp"
android:scrollbarThumbHorizontal="#drawable/border_scroll_listview">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarCampo1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarCampo1" />
</LinearLayout>
<LinearLayout
android:layout_width="80dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarCampo2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarCampo2" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarCampo3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarCampo3" />
</LinearLayout>
<LinearLayout
android:layout_width="30dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblEspacio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_FormatoTar_txtTarSubCampo3" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarSubCampo3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarSubCampo345" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarCampo4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarCampo4" />
</LinearLayout>
<LinearLayout
android:layout_width="30dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblEspacio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_FormatoTar_txtTarSubCampo4" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarSubCampo4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarSubCampo345" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarCampo5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarCampo5" />
</LinearLayout>
<LinearLayout
android:layout_width="30dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblEspacio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_FormatoTar_txtTarSubCampo5" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="#+id/lblTarSubCampo5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LayoutTar_lblTarSubCampo345" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="#+id/lst_PuntoArtFon1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:scrollbarThumbVertical="#drawable/border_scroll_listview"
tools:listitem="#layout/formato_tar_layout"></ListView>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
make background color:white, and clickable = true. This will solve your problem
This is happening because the new view that you are loading(by swiping right/left) is above the HorizontalScrollView & its background colour is transparent. You must give a white background colour to the parent LinearLayout of all the fragments.
Also set android:clickable to true so that the touch events don't trigger the previous fragments.
Make background color: white, and click event as true. This may solve your issue
i'm creating a console or terminal thing, and i'm having a problem. Normaly my Activity looks like this:
but when i click in the edittext and the keyboard opens my edittextfield and my send-button are gone:
but i want the edittext and the sendbutton to be above the keybaord, so you see what you're typing and you're able to send it. This is my xml code:
<?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"
android:background="#d1d1d1">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="477dp"
android:layout_below="#+id/title" >>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:text="Console:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dip"
android:gravity="top"
android:textSize="20sp"
android:textColor="#000000"
android:typeface="monospace"
android:paddingLeft="0dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<EditText
android:layout_marginLeft="5dp"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:id="#+id/consoleText"
android:layout_weight="0.92" />
<Button
android:layout_width="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:text="Send"
android:id="#+id/sendButton"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
Maybe somebody knows, how i can fix this issue! Thanks in advance, any help is appreciated :)
Setting ScrollView's layout_weight=1 should work. Try this
<?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"
android:background="#d1d1d1">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:text="Console:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dip"
android:gravity="top"
android:textSize="20sp"
android:textColor="#000000"
android:typeface="monospace"
android:paddingLeft="0dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_marginLeft="5dp"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:id="#+id/consoleText"
android:layout_weight="0.92" />
<Button
android:layout_width="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:text="Send"
android:id="#+id/sendButton"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
I have a linear layout (linear2 in code) with horizontal orientation.
I've placed a button, editText and a second button into this layout.
I'd like to have the button's width as "wrap_content".
How do I give all the remaining space to editText without using weight?
Is it possible to place this layout to the bottom without using weight
of vertical views?
Code is here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backNormal"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:orientation="vertical"
android:layout_weight="12">
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linear2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2"
android:orientation="horizontal">
<ImageView
android:id="#+id/buttonClip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity= "center_vertical|center_horizontal"/>
<EditText
android:id="#+id/editChatMessage"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:gravity="top|left"
android:maxLines="5"
android:layout_gravity= "center_vertical|center_horizontal"
android:layout_weight="5"/>
<Button
android:id="#+id/buttonProcess"
android:text='Process'
android:gravity="center"
android:layout_gravity= "center_vertical|center_horizontal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Thanks!
Try this way,hope this will help you to solve your problem.
Here i try to improve your LinearLayout weight allocation
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backNormal"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.85">
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linear2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.15"
android:gravity="center">
<ImageView
android:id="#+id/buttonClip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher"
android:scaleType="fitXY"/>
<EditText
android:id="#+id/editChatMessage"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="top|left"
android:maxLines="5"
android:layout_weight="1"/>
<Button
android:id="#+id/buttonProcess"
android:text='Process'
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
Keep your Edittext hight wrap_content.....that's it.
<EditText
android:id="#+id/editChatMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="top|left"
android:maxLines="5"
android:layout_gravity= "center_vertical|center_horizontal"
android:layout_weight="5"
/>
i created button and other...
but now when i want to create a three buttons green,red,blue they are not showing up i want them to be directly down the button1 but they are not showing up i wish you can help me this is the error im getting -xml documents must start and end within the same entity the error is showing in the last last last linearlayout
this is the code im having problem with
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Greetings"
android:textSize="20sp" />
<Button
android:id="#+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:id="#+id/fourthLine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:id="#+id/fifthLine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</RelativeLayout>
</LinearLayout>
this is a picture for the red blue green buttons where to be while mine are down
https://www.dropbox.com/s/73grdc0iff3ql3u/Untitled.png
this is what i reached to till now but i want them to be equally distributed like the picture above
https://www.dropbox.com/s/73grdc0iff3ql3u/Untitled.png
you have not closed the below linear layout tag in your xml.
"<"LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" ">"
You need one more </LinearLayout> at the end of your xml file. At the minute, only 2 of the 3 LinearLayout's are being closed.
EDIT
The reason your Buttons are appearing at the bottom is because of this:
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</RelativeLayout>
I'm not sure what purpose this serves in your application, but removing that will fix your problem.
Replace your xml with following code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
<Button
android:id="#+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="HelloWord" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:weightSum="10" >
<TextView
android:id="#+id/thirdLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.3"
android:background="#ff0000"
android:text="red"
android:textColor="#000000"
android:gravity="center" />
<TextView
android:id="#+id/fourthLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.4"
android:background="#00ff00"
android:text="green"
android:textColor="#000000"
android:gravity="center" />
<TextView
android:id="#+id/fifthLine"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.3"
android:background="#0000ff"
android:text="blue"
android:textColor="#000000"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
Hope it will help you.
rather than explain what's happening, here's a screen-grab:
As you can see my item list is aaaalll over the shop. Going to paste both activity_main.xml and another one that formats the list, list_row.xml
ACTIVITY_MAIN.XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#121212">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/main_title"
android:textColor="#33b5e5"
android:background="#1f1f1f"
android:textStyle="bold"
android:textSize="14sp"/>
<ListView
android:id="#+id/android:list"
android:background="#121212"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="2dip"/>
</LinearLayout>
LIST_ROW.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:background="#121212">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:background="#121212">
<TableRow>
<ImageView
android:id="#+id/icon"
android:padding="2dip"
android:background="#121212"/>
<TextView
android:id="#+id/description"
android:padding="2dip"
android:textSize="18sp"
android:textColor="#ffffff"
android:singleLine="true"
android:background="#121212"/>
</TableRow>
</TableLayout>
</LinearLayout>
Try giving weights to ImageView and TextView like android:layout_weight as the ratio you want.
And dont forget to make android:layout_width = "match_parent" otherwise weights will have no effect..
remove the Table layout
and use this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:background="#121212"
android:orientation="horizontal"
android:padding="6dip" >
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#121212"
android:padding="2dip"
android:src="#drawable/instructions" />
<TextView
android:id="#+id/description"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#121212"
android:padding="2dip"
android:singleLine="true"
android:text="tomer"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>