I want to place a SearchBox above my ListView, but when I do that my EditBox will appear next to my ListView. How can I place it above the ListView?
This is my code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#edf0f4">
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:background="#d0d4db"
android:layout_marginLeft="15px"
android:layout_marginRight="15px"
android:layout_marginTop="15px"
android:hint="Search"
android:textColorHint="#FFFFFF"
android:textColor="#000000" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listview"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="0.0dp" />
To achieve that you will need to set LinearLayout orientation to "Vertical" in order to have EditText above your ListView, like this:
android:orientation="vertical".
and here is a full code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#edf0f4">
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:background="#d0d4db"
android:layout_marginLeft="15px"
android:layout_marginRight="15px"
android:layout_marginTop="15px"
android:hint="Search"
android:textColorHint="#FFFFFF"
android:textColor="#000000" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listview"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="0.0dp" />
</LinearLayout>
Related
I am making a layout within Xamarin Android, but I find a problem and it is that when using a LinearLayout to group a text view and a radio group, the radio group is not generated on the screen only the text view, that is It seems that the radio group did not exist.
This is my Qr.axml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:background="#android:color/white"
android:screenOrientation="portrait"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:screenOrientation="portrait"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/toolbar1"
android:id="#+id/toolbar">
</include>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1014dp"
android:layout_marginLeft="23dp"
android:text="Odometro dañado"
android:visibility="gone"
android:textColor="#android:color/background_dark"
android:id="#+id/Lbl_odometro">
</TextView>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="717dp"
android:layout_marginLeft="15dp"
android:id="#+id/radio_3"
android:orientation="vertical">
<RadioButton
android:id="#+id/radio_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Si"
android:onClick="radioButton_OnClick">
</RadioButton>
<RadioButton
android:id="#+id/radio_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:onClick="radioButton_OnClick">
</RadioButton>
</RadioGroup>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="692dp"
android:layout_marginLeft="255dp"
android:text="Tapa dañada"
android:textColor="#android:color/background_dark"
android:id="#+id/Lbl_Mensaje">
</TextView>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="717dp"
android:layout_marginLeft="255dp"
android:id="#+id/checkbox_meat"
android:orientation="vertical">
<RadioButton
android:id="#+id/checkbox_meat_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Si"
android:onClick="radioButton_OnClick">
</RadioButton>
<RadioButton
android:id="#+id/checkbox_meat_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:onClick="radioButton_OnClick">
</RadioButton>
</RadioGroup>
</LinearLayout>
</RelativeLayout>
</ScrollView>
<EDMTDev.ZXingXamarinAndroid.ZXingScannerView
android:id="#+id/zxscan"
android:layout_above="#+id/layout_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:screenOrientation="portrait">
<EDMTDev.ZXingXamarinAndroid.ZXingScannerView
android:id="#+id/zxscan"
android:layout_above="#+id/layout_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:screenOrientation="portrait"
android:minWidth="25px"
android:minHeight="25px" >
</EDMTDev.ZXingXamarinAndroid.ZXingScannerView>
</EDMTDev.ZXingXamarinAndroid.ZXingScannerView>
<LinearLayout
android:id="#+id/layout_result"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="8dp"
android:background="#android:color/white"
android:visibility = "invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
I tried using a RelativeLayout for grouping, but the problem is that when I generate a background for it, it makes the whole layout get lost.
RadioGroup could do like "LinearLayout". You could try the xml below.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Odometro dañado"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radio_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Si"
android:onClick="radioButton_OnClick">
</RadioButton>
<RadioButton
android:id="#+id/radio_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:onClick="radioButton_OnClick">
</RadioButton>
</RadioGroup>
<TextView
android:text="Tapa dañada"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/checkbox_meat">
<RadioButton
android:id="#+id/checkbox_meat_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Si"
android:onClick="radioButton_OnClick">
</RadioButton>
<RadioButton
android:id="#+id/checkbox_meat_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:onClick="radioButton_OnClick">
</RadioButton>
</RadioGroup>
</RadioGroup>
</ScrollView>
</RelativeLayout >
Screenshot:
I have a problem. I created a ListView with a custom adapter. Therefore I created a new Layout for just 1 row. In that layout I set the main layout to a height of 120dp, but when the list gets created all the rows are not equal and for my opinion not 120dp. Here is the code of the row layout:
<?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:layout_height="120dp"
android:minWidth="0px"
android:minHeight="50px"
android:background="#edf0f4">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="70"
android:layout_height="match_parent"
android:background="#edf0f4"
android:id="#+id/LayoutSettingName">
<TextView
android:text="Dark Theme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtSettingName"
android:textColor="#000000"
android:autoSizeMaxTextSize="20dp"
android:autoSizeMinTextSize="17dp"
android:autoSizeTextType="uniform"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:textStyle="bold" />
<TextView
android:text="Change the theme to something more dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/txtSettingDescription"
android:textColor="#666666"
android:autoSizeMaxTextSize="18dp"
android:autoSizeMinTextSize="16dp"
android:autoSizeTextType="uniform"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_weight="30"
android:layout_height="match_parent"
android:background="#edf0f4"
android:id="#+id/LayoutSettingValue"
android:gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddddd"
android:textColor="#FFFFFF"
android:id="#+id/SettingEditText" />
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/SettingSpinner" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/SettingSwitch" />
</LinearLayout>
</LinearLayout>
Here is a screenshot of the ListView I have right now:
I want to rows to be double the size of the first row, but it doesn't matter which size I give them, they always look like this.
What am I doing wrong?
If you go back through the source code you can see that ListView will call makeAndAddView(... ) to get the View, and in this method, the obtainView method of the parent AbsListView is called, which generates an AbsListView.LayoutParams of MATCH_PARENT width and WRAP_CONTENT height,so the height you set in the item XML doesn't take effect because the ListView defaults to LayoutParams for each item
you could change by the following two ways:
1.Nest the layout in the XML one more time:
<?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:layout_height="match_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="#edf0f4"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="70"
android:layout_height="match_parent"
android:background="#edf0f4"
android:id="#+id/LayoutSettingName">
<TextView
android:text="Dark Theme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtSettingName"
android:textColor="#000000"
android:autoSizeMaxTextSize="20dp"
android:autoSizeMinTextSize="17dp"
android:autoSizeTextType="uniform"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:textStyle="bold" />
<TextView
android:text="Change the theme to something more dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/txtSettingDescription"
android:textColor="#666666"
android:autoSizeMaxTextSize="18dp"
android:autoSizeMinTextSize="16dp"
android:autoSizeTextType="uniform"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_weight="30"
android:layout_height="match_parent"
android:background="#edf0f4"
android:id="#+id/LayoutSettingValue"
android:gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddddd"
android:textColor="#FFFFFF"
android:id="#+id/SettingEditText" />
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/SettingSpinner" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/SettingSwitch" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
2.Manually set an abslistview.layoutparams for convertView in the getView method in Adapter
public override View GetView(int position, View convertView, ViewGroup parent)
{
...
convertView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.layout6, null);
convertView.setLayoutParams(new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 300));//300 is your custom height
...
}
I implemented a barcode scanner in our Xamarin app. To implement the scanner I followed this tutorial: https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/
So, I have a SurfaceView, a CameraSource and a BarcodeDetector. Now I want to crop the camera preview to say the scanner where the barcode in which we have to scan because it is possible that the source from which we can have more than one barcode.
I think this will work with Simple Crop View (or something similar) but I don't how to implement it.
All solutions found here are not working or I'm missing something.
Do you want to acheve it like this GIF?
If so, you could achieve it with ZXing.Net.Mobile
https://github.com/Redth/ZXing.Net.Mobile
There is my demo
https://github.com/851265601/Scanebarcode
Update: If you still want to use the solution like the blew link
https://www.c-sharpcorner.com/article/xamarin-android-qr-code-reader-by-mobile-camera/
I changed the layout like following code. I usd FramLayout, SurfaceView was coverd by other raylout just like LinearLayout or relativelayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<SurfaceView
android:id="#+id/cameraView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:background="#953399ff"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="330dp"
android:orientation="horizontal">
<RelativeLayout
android:background="#953399ff"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<RelativeLayout
android:id="#+id/rlscan"
android:layout_width="220dp"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/area_above_left" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/area_above_right" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="#drawable/area_below_left" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/area_below_right" />
</RelativeLayout>
<RelativeLayout
android:background="#953399ff"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
<RelativeLayout
android:background="#953399ff"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:id="#+id/txtResult"
android:layout_below="#+id/cameraView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please focus Camera to QR Code"
android:textSize="10sp"
android:layout_marginTop="20dp" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
Xamarin Android
I'm trying make slidedown menu.
I don't know, what i'm doing wrong.
I can't position textView like i want.
View should be on the top of screen. However, it's on the bottom.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#f2f2f2">
<RelativeLayout
android:id="#+id/productTitleBar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:background="#ff46a1e1">
<TextView
android:id="#+id/txtProductTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="Product List"
android:layout_gravity="center"
android:clickable="true"
android:layout_centerVertical="true"
android:textSize="18dp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<TextView
android:id="#+id/txtDescription"
android:layout_width="match_parent"
android:layout_height="100dp"
android:textColor="#000000"
android:text="Desription goes here"
android:layout_gravity="center"
android:clickable="true"
android:textSize="18dp"
android:layout_above="#+id/btnImgExpander"
android:background="#FFFFFF"
android:gravity="center"
android:visibility="gone" />
<ImageView
android:id="#+id/btnImgExpander"
android:layout_alignParentBottom="true"
android:layout_height="30dp"
android:layout_width="match_parent"
android:src="#drawable/up_arrow"
android:background="#fff2f2f2" />
<ListView
android:id="#+id/productListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="55dp"
android:layout_marginBottom="30dp"
android:background="#android:color/background_light"
android:fastScrollEnabled="true" />
</RelativeLayout>
I have
I want
Someone can help me with this problem?
android:layout_above="#+id/btnImgExpander" is set on the TextView, but android:layout_alignParentBottom="true" is set on the ImageView, which is aligning it to the bottom of the container (the outer RelativeLayout). You could try: android:layout_alignParentTop="true" and remove the android:layout_alignParentBottom="true"
I writing app for Xamarin Android.
I try to use TextInputLayout
Here is my axml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/main_bck">
<android.support.design.widget.TextInputLayout
android:id="#+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp">
<EditText
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/passwordWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/usernameWrapper"
android:layout_marginTop="5dp">
<EditText
android:id="#+id/username"
android:inputType="textPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="password" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
I need to set Edit Text on center of screen.
How I can do this?
Thanks
Use this in the TextView
android:layout_gravity="center_vertical"
or horizontal
android:layout_gravity="center_horizontal"