Recently I tried to follow these steps: website.
with the casual way of adding the map to be visible into the screen
using this code:
GPSTrackerActivity.java
public class GPSTrackerActivity extends Activity {
private SDCardHandler SDTool;
private ToastSender ToastObject;
private FrameLayout frm_lay;
private MapView myOpenMapView;
private MapController myMapController;
#Override
protected void onCreate(Bundle in) {
super.onCreate(in);
setContentView(R.layout.activity_gpstracker);
SDTool = new SDCardHandler();
ToastObject = new ToastSender(this);
frm_lay = (FrameLayout) findViewById(R.id.frm_lay);
myOpenMapView = (MapView) findViewById(R.id.openmapview);
myOpenMapView.setBuiltInZoomControls(true);
myMapController = myOpenMapView.getController();
myMapController.setZoom(4);
}}
and this one,
activity_gpstracker.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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/default_color" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_desc"
android:textColor="#color/default_color" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_livtr"
android:textColor="#color/default_color" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_curloc"
android:textColor="#color/default_color" />
<FrameLayout
android:id="#+id/frm_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<org.osmdroid.views.MapView
android:id="#+id/openmapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_latitude"
android:textColor="#color/default_color" />
<EditText
android:id="#+id/txt_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_longtitude"
android:textColor="#color/default_color" />
<EditText
android:id="#+id/txt_longtitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gps_altitude"
android:textColor="#color/default_color" />
<EditText
android:id="#+id/txt_altitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</TableRow>
</TableLayout>
</LinearLayout>
but unfortunately, the code above seems giving me nothing.
All components seems normal except the map view, it appeared to be nothing (empty).
And i found noway where to custom the map of my own map into it. Any clues?
You don't follow the tutorial you mention.
Start by following it, and have it working. Then you can introduce changes.
"And i found noway where to custom the map of my own map into it. " => this is a distinct issue, so create a separate question. And if you want an answer, be much (much) more clear about what you want.
Related
This is my first app so sorry I know its not that good. My english neither.
I got a problem with my xml design: I want 2 Buttons and 2 TextViews in one line and to fill the whole line. At the moment it looks like that:
but it gets even worse:
My code:
<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:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
<!--
skipping additional rows of identical structure
-->
</LinearLayout>
The problem is that you use wrap_content on the children of the linear layout. there are 2 solutions to your problem one is to use match parent on the text views and add gravity centre to them like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="-" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="centre"
android:text="TextView" />
<TextView
android:id="#+id/textView13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="centre"
android:text="TextView" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="+" />
</LinearLayout>
And another solution is to use a constraint layout with allows you to spread the child views using chains.
If I understood correctly, you should try for each of your LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4" // number of sub items
>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/textView11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<Button
android:id="#+id/button11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
Also, you should take a look at RecyclerViews and create your own adapter and rows. It will be much easier to deal with.
How can I put the image view below two of the text views, tv_pw and tv_un. So that in the layout the two text views are on top of the image, while the image serves as a background for that two text views. How could I do that?
Here is my xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="510dip"
android:layout_marginTop="10dip"
android:background="#DDDDDD">"
<EditText
android:id="#+id/et_pw"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_un"
android:layout_below="#+id/et_un"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="#+id/tv_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/et_pw"
android:layout_alignBottom="#+id/et_pw"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/et_pw"
android:text="Password:"
android:textColor="#444444"
android:textSize="10pt" />
<Button
android:id="#+id/btn_login"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_below="#+id/et_pw"
android:layout_centerHorizontal="true"
android:text="Login" />
<TextView
android:id="#+id/tv_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/tv_pw"
android:layout_marginTop="98dp"
android:text="User Name:"
android:textColor="#444444"
android:textSize="10pt" />
<EditText
android:id="#+id/et_un"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv_un"
android:layout_centerHorizontal="true"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btn_login"
android:layout_centerHorizontal="true"
android:text="" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:src="#drawable/bkground" />
There's a lot more in your XML but, focusing on what you are asking, you can use the margin attribute to overlap the textviews.
Try something like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImage">
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/image"
android:layout_marginTop="-50dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world2" />
</LinearLayout>
</RelativeLayout>
In this example I wrapped the two textviews inside a linear-layout (vertical) and set the linear-layout below the imageview and a margin of -50dp so it goes up and overlap.
HIH
Another way would be to use drawableBottom="#drawable/ic_launcher" inside your textview
If you don't care about having control on how the image scales, you can set the background of a LinearLayout that's wrapped around the TextViews.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/your_background_image_here"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_2" />
</LinearLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="510dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:gravity="center"
android:background="#DDDDDD">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="98dp">
<LinearLayout
android:layout_width="110dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bkground">
<TextView
android:id="#+id/tv_un"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User Name:"
android:textColor="#444444"
android:textSize="10pt" />
<TextView
android:id="#+id/tv_pw"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="Password:"
android:textColor="#444444"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp">
<EditText
android:id="#+id/et_un"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="text" />
<EditText
android:id="#+id/et_pw"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btn_login"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Login" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Wrap the two TextViews in linear layout with vertical orientation and assign background for linear layout.
use android:weight on the the two text views and boom
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Am trying to achieve the below layout on Android (Target API 18, min API 8)
Am relatively new to Android & came up with below layout file (activity_main.xml). I know a bit about Linear versus Relative layout and would highly appreciate if anyone can provide some input in this direction.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/task_name"
android:textSize="14sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:ems="10"
android:hint="#string/task_name_hint"
android:inputType="text" />
<DatePicker
android:id="#+id/dpResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:layout_marginTop="8dp" />
<RadioGroup
android:id="#+id/priority_radios"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/dpResult"
android:inputType="text"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/first_radio" />
<RadioButton
android:id="#+id/second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/second_radio"/>
<RadioButton
android:id="#+id/third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/third_radio" />
<RadioButton
android:id="#+id/none"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/none_radio"
android:checked="true" />
</RadioGroup>
<RadioGroup
android:id="#+id/category_radios"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/priority_radios"
android:inputType="text"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/long_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/first_radio" />
<RadioButton
android:id="#+id/short_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/second_radio"/>
<RadioButton
android:id="#+id/new_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/third_radio" />
</RadioGroup>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tag_name"
android:textSize="14sp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/tag_arrays"
android:prompt="#string/tag_prompt"
android:layout_below="#id/category_radios"
android:layout_toRightOf="#id/textView2" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner1"
android:text="#string/create_task" />
</RelativeLayout>
It seems a fairly easily layout. You can use a vertical parent linearlayout, and then several horizontal linearlayout for each row.
<?xml version="1.0" encoding="utf-8"?>
<!-- PARENT LAYOUT -->
<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/line1"
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:text="Task name"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter task name"/>
</LinearLayout>
<LinearLayout android:id="#+id/line2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- SECOND LINE -->
</LinearLayout>
<LinearLayout android:id="#+id/line3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- THIRD LINE -->
</LinearLayout>
I'd use a RelativeLayout as you do, for the container, then some LinearLayouts and RadioGroups (which inherit from LinearLayout)
Now this is the result I got (note that I left the central part empty)
- no matter if I used a picture that looks like a combo for the textview (it's just a 9 patch I had handy) and the images don't match with yours...
By using this layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ccc"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.5"
android:layout_margin="4dp"
>
<ImageButton
android:id="#+id/imgBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_margin="4dp"
/>
<ImageButton
android:id="#+id/imgFore"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toRightOf="#id/imgBack"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_margin="4dp"
/>
<ImageButton
android:id="#+id/imgExit"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toRightOf="#id/imgFore"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_margin="4dp"
/>
<ImageButton
android:id="#+id/imgHome"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toRightOf="#id/imgExit"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_margin="4dp"
/>
<ImageButton
android:id="#+id/imgFind"
android:layout_width="32dp"
android:layout_height="24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_margin="4dp"
/>
<TextView
android:id="#+id/txtAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imgHome"
android:layout_toLeftOf="#id/imgFind"
android:layout_centerVertical="true"
android:background="#drawable/combo_opt_m"
android:layout_margin="4dp"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="7.5"
android:background="#fff"
>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<ImageButton
android:id="#+id/imgFoot"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_margin="4dp"
/>
</RelativeLayout>
</LinearLayout>
please note that, in my onCreate method, I used:
#Override
protected void onCreate(
final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Make this activity, full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Hide the Title bar of this activity screen
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.form);
}
In order to make the app fullscreen
I have the following XML code (partial for this example purposes):
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="0dp"
android:paddingRight="0dp" >
<RadioGroup
android:id="#+id/rgVehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5" >
<RadioButton
android:id="#+id/rbCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Car" />
<RadioButton
android:id="#+id/rbTruck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Truck" />
<RadioButton
android:id="#+id/rbCycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Motorcycle" />
</RadioGroup>
<EditText
android:id="#+id/etToll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:layout_weight=".5" />
</LinearLayout>
For smaller screen like Galaxy Nexus and Nexus One the layout comes out like this:
How do I fix it so the EditText is directly below the #6 label as shown below (no matter what size the screen is):
There you go:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5. Vehicle type"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="#+id/rgVehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/rbCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Car" />
<RadioButton
android:id="#+id/rbTruck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Truck" />
<RadioButton
android:id="#+id/rbCycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Motorcycle" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6. Total amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/etToll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
</LinearLayout>
</LinearLayout>
Use something like this:
<tablelayout>
<tablerow android:layout_weightsum="2">
<textview android:layout_weight="1" android:text="4">
<textview android:layout_weight="1" android:text="6">
</tablerow>
<tablerow android:layout_weightsum="2">
<radiogroup android:layout_weight="1">
<!-- add radio buttons here -->
</radiogroup>
<edittext android:layout_weight="1" >
</tablerow>
</tablelayout>
once more: me.
I have a TableLayout (http://imgur.com/XYdcg) for my "SingleItemAdvancedView" how i like to call it ;)
The thing is, I want the data [the TextViews which don't have string *Lbl as android:text set] (so NOT the description like : "name:" , "id:" etc.) to be displayed on the right side of the whole display, not like it's now ( they are displayed right next to the left table-column). I tried to align the layout to the right side, as well as only the text (with layout_gravity and gravity only). everything didn't work. My widths are all set to fill_parent , so I simply don't understand why. Help needed! Thanks!
My XML for the activity looks like this:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="#string/idLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/itemidv" />
</TableRow>
<TableRow>
<TextView android:text="#string/nameLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/namev" />
</TableRow>
<TableRow>
<TextView android:text="#string/amountLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/amountv" />
</TableRow>
<TableRow>
<TextView android:text="#string/unitLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/unitv" />
</TableRow>
<TableRow>
<TextView android:text="#string/ppuLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ppuv" />
</TableRow>
<TableRow>
<TextView android:text="#string/totalLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/totalv" />
</TableRow>
<TableRow>
<TextView android:text="#string/commentLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/commentv" />
</TableRow>
<TableRow>
<TextView android:text="#string/enterqrLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/qrcodev" />
</TableRow>
<Button android:text="#string/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/deleteItemBtn"
android:layout_marginTop="20dp"
android:onClick="btnListener" />
</TableLayout>
You could add android:stretchColumns="0" to TableLayout. So you would have something like this:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0">
If you want both columns to stretch equally you could use '*' instead of '0'.