This is a Very simple layout I hope to achieve on. However, I tried many ways to make my customView appear at the side of the Buttons - LinearLayout. But I failed. Any help would be greatly appreciated!
Thank you!
This is where I declare my CustomView at MainActivity.
public class Drawing extends Activity {
mContent = (LinearLayout) findViewById(R.id.labelCreator);
mSignature = new Resize(this, null);
mContent.addView(mSignature);
...........
My XML Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/Drawing"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible" >
<LinearLayout
android:id="#+id/interface2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginTop="0dp"
android:background="#8b5a2b"
android:orientation="horizontal" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/camera2"
android:text="Camera"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/image"
android:text="Image"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/text"
android:text="Text"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<EditText
android:id="#+id/editText1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="false"
android:hint="text"
android:maxLength="10"
android:maxLines="1"
android:textAlignment="center"
android:textColor="#e6e6fa"
android:textSize="25sp"
android:typeface="serif"
android:visibility="visible" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Spinner
android:id="#+id/color_spinner"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:textAlignment="center" />
<Spinner
android:id="#+id/fonts_spinner"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:textAlignment="center"
app:context=".LabelCreator" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/save3"
android:text="Save"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/clear"
android:text="Clear"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
</TableRow>
</TableLayout>
</TableRow>
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/close"
android:shadowColor="#00000000"
android:text="Close"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
</TableLayout>
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="250dp"
android:layout_height="85dp"
android:maxLines="1"
android:singleLine="true"
android:text="TextView"
android:textSize="20sp"
android:visibility="invisible" />
</LinearLayout>
This is just a structure to follow
<?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:weightSum="10" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="vertical" >
<Button
android:id="#+id/btnSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/save3"
android:text="Save"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="#+id/btnClear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/clear"
android:text="Clear"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="serif" />
<Spinner
android:id="#+id/color_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center" />
<Spinner
android:id="#+id/fonts_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
app:context=".LabelCreator" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="7" >
// your custom view(Drawing area) will be here.
</LinearLayout>
</LinearLayout>
Here the parent layout has android:orientation="horizontal" so all its child layout will display in column-wise.
If you want row-wise display make android:orientation="vertical". Here I use vertical for the parent layout that have <Button> and <Spinner> controls.
you will make changes in it as per your need.
Hope this will help.
Related
I am trying to add a table inside a linear layout. Inside my linear layout there is textview, spinner. When I try to add a table layout it doesn't align correctly. Below is my code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/cardLayout"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product"
android:gravity="center"
android:textStyle="bold"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_margin="10sp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<Spinner
android:id="#+id/product_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Product Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sale" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
Output
Expected Output
I must be missing something that I don't know. How can I align them equally just like in the above image
Any help would be highly appreciated.
Try using below code:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product"
android:gravity="center"
android:textStyle="bold"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<Spinner
android:id="#+id/product_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center"
>
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Product Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sale" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
I am experiencing some strange behaviour with my layouts. As you can see from the screenshot below (of the layout in eclipse) the 'register' button appears just fine at the bottom of the screen.
Before
However, if you now take a look at the following screenshot taken on my phone (HTC ONE X) whilst debugging, the button is completely cut off with plenty of space.
After
The code for the register page is as follows (where the button is contained within the relative layout)
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Register"
android:textSize="18sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Title:" />
<EditText
android:id="#+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="First Name:" />
<EditText
android:id="#+id/txtFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Surname:" />
<EditText
android:id="#+id/txtSurname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Email:" />
<EditText
android:id="#+id/txtEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Age:" />
<EditText
android:id="#+id/txtAge"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:stretchColumns="*"
android:weightSum="4" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/txtGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Gender" />
<TextView
android:id="#+id/txtTypeOfUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Type of User" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<RadioGroup
android:id="#+id/radioTypeOfUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="User" />
<RadioButton
android:id="#+id/radioDoctor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Doctor" />
</RadioGroup>
</TableRow>
</TableLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:text="Register" />
</RelativeLayout>
</LinearLayout>
Your TableLayout has layout_height set to fill_parent, change it to wrap_content.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:stretchColumns="*"
android:weightSum="4" >
I'm going crazy with a activity design
I think thah the problem is with the Weights atributes but I'm not sure. The fields of the row on middle contains letters hidding and the button size expands to height (not respond to changes in width and height atributes)
The span atributes is correctly assigned?
This is a snapshot of the activity
This is a summary of the estructure
LinearLayout 1
LinearLayout 1.1
TableLayout
TableRow
LinearLayout 1.2
TableLayout
TableRow con imagen centrada (span=4)
TableRow con 4 Textviews
TableRow con un textview que se modifica(span =2) y un boton de continuar (span=2)
LinearLayout 1.3
TextView
Wich effect have really the weight attribute in nested layouts?
This is the code of activity
<?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="#drawable/gradient"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp" >
<TableRow android:layout_gravity="center_vertical" >
<ImageView
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:contentDescription="#string/info_pm2"
android:src="#drawable/infomdpi2" />
<TextView
android:id="#+id/info_pm1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/pm3_3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:background="#drawable/roundcorners"
android:gravity="center_horizontal"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="15dp" >
<TableRow
android:layout_weight="5"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/instrtutpm1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:layout_weight="1"
android:contentDescription="#string/logo"
android:paddingTop="5dp"
android:src="#drawable/t3_3" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/BtnOption0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="A"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="B"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="C"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:text="D"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="center_vertical|right" >
<TextView
android:id="#+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:textStyle="bold" />
<Button
android:id="#+id/BtnNextQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:text="#string/next" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center|right" >
<TextView
android:id="#+id/large_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/large_appname"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Thanks a lot
Just remove android:layout_span="4" from Button Widget
In your code I observed the button has android:layout_span="4" If you remove this attribute for the button and for textview and make the TableRow to
<TableRow
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center_vertical|right" >
<TextView
android:id="#+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<Button
android:id="#+id/BtnNextQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</TableRow>
// 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:gravity="center_vertical"
android:background="#android:color/holo_blue_light"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:contentDescription="info_pm2"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/info_pm1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="pm3_3"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="25dp">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/instrtutpm1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:contentDescription="logo"
android:paddingTop="5dp"
android:src="#drawable/ic_launcher" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" r>
<TextView
android:id="#+id/BtnOption0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="A"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="B"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="C"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/BtnOption3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="D"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/respuesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<Button
android:id="#+id/BtnNextQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center|right" >
<TextView
android:id="#+id/large_appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="large_appname"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>-->
</LinearLayout>
i wan tto create sccreen like this image http://imgur.com/UVKCZdu my screen url is looklike this http://imgur.com/gLQw4iV
my screen not adjust facebook twitter iccon also show space on bottom below 3 buttons how do i fixed them? help me below is my xml 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:background="#ffffff"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#C0C0C0" >
<ImageView
android:id="#+id/test_button_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingTop="5dp"
android:src="#drawable/icon" >
</ImageView>
<TextView
android:id="#+id/test_button_text2"
android:layout_width="wrap_content"
android:paddingTop="10dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/test_button_image"
android:paddingLeft="10dp"
android:layout_toRightOf="#+id/test_button_image"
android:text="San Diego Unified"
android:textColor="#000000"
android:textSize="20sp" >
</TextView>
<TextView
android:id="#+id/test_button_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:layout_alignLeft="#+id/test_button_text2"
android:layout_below="#+id/test_button_text2"
android:paddingBottom="10dp"
android:text="SCHOOL DISTRICT"
android:textColor="#000000" >
</TextView>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
a
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="HEALTHY BODIES HEALTHY MINDS "
android:textColor="#000000"
android:textSize="12sp" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="#drawable/facebook" />
<ImageButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="#drawable/twitter"
android:text="Button Text" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Search School By Name"
android:layout_centerVertical="true" >
</EditText>
<ImageView
android:id="#+id/imageView1"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignRight="#+id/editText1"
android:src="#drawable/title_search" />
</RelativeLayout>
<TextView
android:id="#+id/txtCaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingBottom="3dp"
android:paddingLeft="10dp"
android:paddingTop="3dp"
android:text="SELECT A SCHOOL TO VIEW LUNCH OR BREAKFAST MENUS"
android:textColor="#000000"
android:textSize="10sp"
android:textStyle="bold" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#000000" />
<LinearLayout
android:id="#+id/lytContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/txtCopyright"
android:background="#ffffff"
android:layout_below="#+id/lytTitlebar"
android:orientation="vertical" >
<ListView
android:id="#+id/listMainMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/background"
android:dividerHeight="1dip"
android:fadeScrollbars="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#a8a8a8"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a8a8a8"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:background="#drawable/button_style"
android:text="FARM TO SCHOOL"
android:textColor="#color/text"
android:textSize="8sp"
android:textStyle="bold" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:background="#drawable/button_style"
android:text="TAKE A SURVEY"
android:textColor="#color/text"
android:textSize="8sp"
android:textStyle="bold" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:background="#drawable/button_style"
android:text="SHARE THIS APP"
android:textColor="#color/text"
android:textSize="8sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can't setText in an ImageView.. that's just for TextViews
What you can do instead is wrap an ImageView and a TextView inside a FrameLayout, then do your setText on the TextView. Make sure you define the ImageView first, so it's below the TextView's z-order.
Add image to text view like this:
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawableRight="#drawable/protection_unprotected"
android:gravity="center_vertical"
android:paddingRight="5dp"
android:text="#string/protection_unprotected"
android:textSize="18sp"
android:textStyle="bold" />
android:drawableRight="#drawable/protection_unprotected"
For your Facebook and Twitter buttons you can add
android:background = "#null"
inside ImageButton tags for the unwanted background in buttons.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#a8a8a8"
android:orientation="horizontal" >
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/headerLinearLay"
android:orientation="horizontal">
<ImageView
android:id="#+id/avatarImageView"
android:src="#drawable/icon"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<TextView
android:id="#+id/usernameTextView"
android:text="TextView"
android:paddingLeft="4dp"
android:layout_toRightOf="#id/avatarImageView"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></TextView>
</RelativeLayout>
</LinearLayout>
Im new in andorid.I put textview to set data from mymethods.But it goes force close.But I tried it in another activity page my code worked.So ı suspected my xml layout .does anyone take care of this problem ,if so I will be very gratefull.Thanks Here are my layout.xml and my codes:
String iskate=WorkCat.Kategori(Workid);
iskat.setText(iskate);
Log.d("işkategorisi",iskate);
and Log.cat shows true value.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/backgrund" >
<!-- Header Starts -->
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentTop="true"
android:background="#layout/header" >
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:background="#layout/footer" >
<ImageView
android:id="#+id/imagegeri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="220dp"
android:src="#drawable/geri" />
<ImageView
android:id="#+id/imagecikis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/cikis" />
</LinearLayout>
<TextView
android:id="#+id/textAD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/header"
android:layout_alignParentRight="true"
android:layout_marginBottom="14dp"
android:layout_marginRight="26dp"
android:text="Small Text"
android:textSize="13dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
<LinearLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/footer"
android:layout_below="#id/textAD" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/header"
android:orientation="vertical"
android:padding="10dip" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="İş Kategorisi"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:id="#+id/txtiskate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rfyr"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aşama"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" >
</Spinner>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Görevli"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
<AutoCompleteTextView
android:id="#+id/Searchname"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</AutoCompleteTextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Öncelik"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" >
</Spinner>
</TableRow>
<EditText
android:id="#+id/edituacikla"
android:layout_width="290dp"
android:layout_height="140dp"
android:ems="10"
android:inputType="textMultiLine" />
<TableRow>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gerçekleşen Süre"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
<EditText
android:id="#+id/edittoplm"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView6"
android:layout_alignBottom="#+id/textView6"
android:layout_alignLeft="#+id/spinner4"
android:ems="10"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Saat"
android:textAppearance="?android:attr/textAppearanceSmall" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tamamlanan(%)"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner5"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentLeft="true" >
</Spinner>
</TableRow>
<TableRow>
<Button
android:id="#+id/btnvzgec"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="Vazgec" />
<Button
android:id="#+id/uwgncelle"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Güncelle" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
Initialize your Text View first
TextView iskat = (TextView)findViewById(R.id.txtiskate);
String iskate=WorkCat.Kategori(Workid);
iskat.setText(iskate);
First you need to initialize your textview then after you can use it. Try below code.
TextView iskat = (TextView)findViewById(R.id.txtiskate);
String iskate=WorkCat.Kategori(Workid);
iskat.setText(iskate);
'iskate' should be instance of a 'TextView' like iskate=(TextView)(TextView)findViewById(id of the layout in xml here);
in your case its a string how is this possible this will show compile time error.