Multiple and different counters in one activity - java

Basically I need a TableLayout which contains multiple rows and in every row there must be a different counter (which I can add or subtract 1 by pressing one of the two buttons in the row).
Here you can see a clear example:
content_main.xml
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="55dp">
<TextView
android:text="Pizza Margherita"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView27"
android:layout_weight="10"
android:layout_column="1" />
<Button
android:text="-"
android:layout_height="wrap_content"
android:id="#+id/minusButton"
android:layout_weight="1"
android:layout_column="1"
android:layout_width="50dp" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/result"
android:layout_weight="5"
android:layout_column="1"
android:textAlignment="center" />
<Button
android:text="+"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/plusButton"
android:elevation="0dp"
android:layout_weight="0.5"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp">
<TextView
android:text="Pizza Salame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView27"
android:layout_weight="10"
android:layout_column="1" />
<Button
android:text="-"
android:layout_height="wrap_content"
android:id="#+id/minusButton2"
android:layout_weight="1"
android:layout_column="1"
android:layout_width="50dp" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/result2"
android:layout_weight="5"
android:layout_column="1"
android:textAlignment="center" />
<Button
android:text="+"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/plusButton2"
android:elevation="0dp"
android:layout_weight="0.5"
android:layout_column="1" />
</TableRow>
</TableLayout>
I have no idea how to work on MainActivity.java.
By far I tried to implement an array (without success) and write a separate class for every single counter (but it resulted too redundant).
Any tips?

If I understood correctly your question, I'd suggest to you to implement a custom view logic for your counter and and adapter to turn it more scalable.
Basically you'll have:
counter_layout.xml - Declare the components
CounterView.java - Inflate the layout and control the logic of counter
CounterAdapter.java - Instantiate a multiple intances of a CounterView
Then, you could use an ListView in your Activity that will show the adapter's content.
Ofcourse that you will need manage the state of each CounterView. But it is easy and maybe it'd be a next step of your project.

Related

why doesn't my banner appear in Linearlayout?

I am using relative layout in linear layout.My banner appears on the design screen, but no ads appear when I run my application.I looked at many examples but I could not find.My application was horizontal before now I'm designing vertically.Previously I was using Relativelayout then my banner was working.Here my code;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:weightSum="12"
android:background="#fffdd0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2">
<RelativeLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btn_double"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:background="#drawable/xx"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_yariyariya"
android:layout_width="47dp"
android:layout_height="47dp"
android:background="#drawable/fiftyfifty"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_skip"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:background="#drawable/skip"
android:layout_marginTop="15dp"/>
<TextView
android:id="#+id/tv_countdown2x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_alignParentStart="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_double" />
<TextView
android:id="#+id/tv_countdown50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_yariyariya"/>
<TextView
android:id="#+id/tv_countdownNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_alignParentEnd="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_skip"/>
<TextView
android:id="#+id/tv_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="00:30"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimary"
android:layout_marginTop="85dp" />
<FrameLayout
android:id="#+id/container_pop_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp" />
</RelativeLayout>
<TextView
android:id="#+id/tv_countdown1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginStart="40dp"
android:layout_marginTop="60dp"
android:textColor="#color/colorPrimary"/>
<Button
android:id="#+id/btn_kalp1"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/kalp"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_satinal"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_marginStart="200dp"
android:onClick="satinalMain"
android:background="#drawable/satinal"
android:layout_alignParentEnd="true"
android:layout_marginEnd="30dp"
android:layout_marginTop="15dp"/>
<TextView
android:id="#+id/tv_kalp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="5"
android:textColor="#color/colorPrimary"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:layout_marginStart="84dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:text="X"
android:textColor="#color/colorPrimary"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp"
android:layout_marginStart="77dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3">
<TextView
android:id="#+id/tv_soru"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:fontFamily="#font/incee"
android:gravity="center"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:textAlignment="gravity"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="5"
android:orientation="vertical">
<Button
android:id="#+id/btn_a"
android:layout_width="260dp"
android:layout_height="60dp"
android:textColor="#000"
android:background="#drawable/gradient"
android:gravity="center"
android:textAlignment="gravity"
android:fontFamily="#font/incee"
android:textSize="12sp"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/btn_b"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_below="#+id/btn_a"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#drawable/gradient"
android:fontFamily="#font/incee"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="#000"
android:textSize="12sp" />
<Button
android:id="#+id/btn_c"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:background="#drawable/gradient"
android:fontFamily="#font/incee"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="#000"
android:textSize="12sp"
android:layout_below="#+id/btn_b"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/btn_d"
android:layout_width="260dp"
android:layout_height="60dp"
android:textColor="#000"
android:background="#drawable/gradient"
android:gravity="center"
android:textAlignment="gravity"
android:fontFamily="#font/incee"
android:textSize="12sp"
android:layout_below="#+id/btn_c"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/btn_infoA"
android:layout_width="40dp"
android:layout_height="45dp"
android:background="#drawable/info"
android:layout_centerVertical="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/btn_gec"
android:layout_width="65dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="1dp"
android:background="#drawable/next"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_skor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="0"
android:textColor="#000"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:text="SKOR :"
android:textColor="#000"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"/>
<Button
android:id="#+id/btn_reklam"
android:layout_width="50dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:background="#drawable/plus"
android:onClick="startVideoAd"/>
<TextView
android:id="#+id/tv_kalp_kazan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="İzle Kazan"
android:layout_alignParentStart="true"
android:textSize="15sp"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:fontFamily="#font/incee"
android:textColor="#000"
android:layout_marginStart="55dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3101578796185185/4912585915">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
I think it's because the bannerview is lower than your screen! (Maybe you're using this layout for a fragment and your activity has a toolbar, am I right?)
Just put LinearLayout inside a ScrollView and see if it works.
Your layout design is not very well done, the buttons at the center (first RelativeLayout) are not constrained to the adjacent buttons, so they may overlap.
You should use a ConstraintLayout instead of RelativeLayout, the later is obsolete now.
You have several items with wrap_content height inside a layout that you want to stretch vertically, which is contradictory. This may cause views inside the inner RelativeLayouts to be hidden if they are smaller than the height.
weightSum is a property that is rarely useful because weights are calculated automatically, you should simply know that two views with 1 and 1 with use 50% each, and if you add another with weight 2 it will have proportionally that weight. So it will end up 25%, 25% and 50%.
There is no need to place the AdView inside a RelativeLayout if it is the only view there.
If you want the banner to be always visible, then simply place a default height (either wrap_content or a given height in dps). The other views will use the remaining space to calculate the weight space.
I recommend you to first study how different Layouts work before attempting to build your screen layout.
On the other hand, the AdView requires some additional configuration on your end to become shown, because if you did not setup some campaign to be shown, the view won't display anything.

Change the text size of a TextView and a Column in TableLayout in Android

This is the layout
As you can see, I'm trying to stretch the text box so it will be next to the "NOPE" button. I'm being restricted by the column's size, and the text box's size, which I don't know how to change.
XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/editBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_column="2"
android:onClick="editEvent"
android:text="EDIT" />
<TextView
android:id="#+id/attendingEventInListviewRow"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_column="38"
android:height="30sp"
android:tag="Events2goName"
android:text="Events2go"
android:textColor="#000000"
android:textSize="22sp"
android:textStyle="normal" />
<Button
android:id="#+id/cancel_arrive"
style="?android:attr/buttonStyleSmall"
android:layout_width="130dp"
android:layout_height="36dp"
android:layout_column="37"
android:layout_gravity="right"
android:layout_weight="0.08"
android:onClick="selectCancelArrive"
android:text="Nope" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableRow>
If you set width with hard code using dp it will not work properly with multiple screen. I don't know which screen size you testing you app .. you can set TextView android:layout_width="100dp" it will work for you I hope..
But best is
You can set android:weightSum in TableRow and set android:layout_weight Views under TableRow ... below code is done for you. And it will fit with all screen size..
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="10">
<Button
android:id="#+id/editBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_column="2"
android:layout_weight="2"
android:onClick="editEvent"
android:text="EDIT" />
<TextView
android:id="#+id/attendingEventInListviewRow"
android:layout_width="0dp"
android:layout_weight="6"
android:layout_height="wrap_content"
android:layout_column="38"
android:height="30sp"
android:tag="Events2goName"
android:text="Events2go"
android:textColor="#000000"
android:textSize="22sp"
android:textStyle="normal" />
<Button
android:id="#+id/cancel_arrive"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="36dp"
android:layout_column="37"
android:layout_gravity="right"
android:layout_weight="0.08"
android:onClick="selectCancelArrive"
android:text="Nope" />
</TableRow>
try this...
<TextView
android:id="#+id/attendingEventInListviewRow"
android:layout_width="0dp"
android:layout_weight=""
android:layout_height="wrap_content"
android:layout_column="38"
android:height="30sp"
android:tag="Events2goName"
android:text="Events2go"
android:textColor="#000000"
android:textSize="22sp"
android:textStyle="normal" />
For example, if you have 3 columns (100% weight) and you want the first column use a 40% of the total weight, put android:layout_weight="0.4",if the second column use a 50% put android:layout_weight="0.5" and the 3rd and last column uses 10% default android:layout_weight="0.1"

Android studio setting layout up like this

I've tried everything I can think of but can't get this layout working. It's a ListView that list matches in a row.
Row one is first match, and next row is second match, and so on. I don't don't mind the green strokes and borders.
Is it even possible?
See the deisgn here:
Here's an example implementation, it does however use negative margins, to overlap the thing I called badge.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cdcdcd"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/score"
android:layout_below="#+id/badge"
android:background="#color/white"
android:orientation="vertical"
android:padding="16dp"
android:showDividers="middle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2"/>
</LinearLayout>
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="16dp"
android:text="0 vs 7"
android:layout_below="#+id/badge"
android:textSize="32sp"
android:textStyle="bold"/>
<LinearLayout
android:layout_below="#+id/badge"
android:id="#+id/right_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/score"
android:background="#color/white"
android:orientation="vertical"
android:padding="16dp"
android:showDividers="middle">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2"/>
</LinearLayout>
<TextView
android:id="#+id/badge"
android:layout_toRightOf="#id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0f0"
android:layout_marginLeft="-12dp"
android:layout_marginBottom="-8dp"
android:text="Badge"
/>
</RelativeLayout>
To alternate the background simply set the background in getView in your adapter.
You'll need a custom adapter that fills the ListView (better use RecyclerView & an Adapter with ViehHolder), this row layout is taken from my own project, not exactly what you requested, but you'll get the idea. Just comment for further information.
<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="wrap_content"
>
<TextView
android:id="#+id/textV_player1"
android:text="player1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:textSize="20sp"
android:paddingTop="15dp"
android:gravity="end"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/textV_vs"
android:layout_toStartOf="#+id/textV_vs" />
<TextView
android:id="#+id/textV_player2"
android:text="player2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="15dp"
android:layout_alignBottom="#+id/textV_vs"
android:layout_toRightOf="#+id/textV_vs"
android:layout_toEndOf="#+id/textV_vs" />
<TextView
android:id="#+id/textV_vs"
android:text="vs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:textSize="20sp"
android:layout_above="#+id/textV_points1"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/textV_points1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="3dp"
android:paddingBottom="15dp"
android:layout_below="#+id/textV_player1"
android:layout_alignRight="#+id/textV_player1"
android:layout_alignEnd="#+id/textV_player1" />
<TextView
android:id="#+id/textV_points2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="3dp"
android:paddingBottom="15dp"
android:layout_below="#+id/textV_player2"
android:layout_alignLeft="#+id/textV_player2"
android:layout_alignStart="#+id/textV_player2" />
<TextView
android:id="#+id/textV_vspoints"
android:text=":"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingBottom="15dp"
android:layout_below="#id/textV_vs"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Implementing an adapter for RecyclerView in Android

I am trying to implement the flexible space with image pattern of the material design.
In order to do so, I followed this tutorial.
The problem is, the tutorial uses RecyclerView, and I have another view I'd like to use which is just a simple ScrollView with a relative view:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<TextView
android:id="#+id/loggedInTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/separator1"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:text="#string/profile_logged_in_with_title"
android:textSize="18sp" />
<ImageView
android:id="#+id/loggedInPlatformLogo"
android:layout_width="95dp"
android:layout_height="30dp"
android:layout_alignBottom="#+id/loggedInTitle"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-4dp"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/loggedInTitle"
android:background="#drawable/facebook_logo"
android:gravity="center_horizontal|center_vertical" />
<View
android:id="#+id/separator2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignLeft="#+id/separator1"
android:layout_below="#+id/loggedInTitle"
android:layout_marginTop="17dp"
android:background="#android:color/darker_gray" />
<ImageView
android:id="#+id/homeIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/loggedInTitle"
android:layout_below="#+id/separator2"
android:layout_marginTop="10dp"
android:background="#drawable/home_icon" />
<TextView
android:id="#+id/homeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/homeIcon"
android:layout_marginBottom="4dp"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/homeIcon"
android:text="#string/profile_home_title"
android:textSize="18sp"
android:textStyle="bold" />
<AutoCompleteTextView
android:id="#+id/homeAddressEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/homeIcon"
android:layout_below="#+id/homeIcon"
android:layout_marginTop="2dp"
android:ems="10"
android:hint="#string/profile_home_address_hint"
android:inputType="textAutoComplete"
android:textSize="16sp" />
<View
android:id="#+id/separator3"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignLeft="#+id/separator1"
android:layout_below="#+id/homeAddressEdit"
android:layout_marginTop="8dp"
android:background="#android:color/darker_gray" />
<ImageView
android:id="#+id/workIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/homeIcon"
android:layout_below="#+id/separator3"
android:layout_marginTop="10dp"
android:background="#drawable/work_icon" />
<TextView
android:id="#+id/workTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/workIcon"
android:layout_marginBottom="4dp"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/workIcon"
android:text="#string/profile_work_title"
android:textSize="18sp"
android:textStyle="bold" />
<AutoCompleteTextView
android:id="#+id/workAddressEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/workIcon"
android:layout_below="#+id/workIcon"
android:layout_marginTop="2dp"
android:ems="10"
android:hint="#string/profile_work_address_hint"
android:inputType="textAutoComplete"
android:textSize="16sp" />
<View
android:id="#+id/separator4"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignLeft="#+id/separator1"
android:layout_below="#+id/workAddressEdit"
android:layout_marginTop="8dp"
android:background="#android:color/darker_gray" />
<ImageView
android:id="#+id/privacyIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/workIcon"
android:layout_below="#+id/separator4"
android:layout_marginTop="13dp"
android:background="#drawable/privacy_icon" />
<TextView
android:id="#+id/privacyTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/privacyIcon"
android:layout_marginBottom="4dp"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/privacyIcon"
android:text="#string/profile_privacy_title"
android:textSize="18sp"
android:textStyle="bold" />
<Spinner
android:id="#+id/privacySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/privacyIcon"
android:layout_below="#+id/privacyIcon"
android:layout_marginBottom="4dp"
android:layout_marginTop="-3dp"
android:entries="#array/profile_privacy_settings"
android:prompt="#string/profile_privacy_title" />
</RelativeLayout>
</ScrollView>
So I tried to replace the RecyclerView in the tutorial's layout xml with a reference to this view, but the result is I can't scroll the view. I guess that's because ScrollView is not compatible with the flexible space pattern.
Next attempt was trying to convert the above ScrollView layout to an adapter in order to use RecyclerView following this Android Developers example, but I have no idea how to do that, since I got too many elements to combine and the example consists of simple array of Strings.
I'd really appreciate a sample of how the Adapter should look like in order to match the layout above, or another easier solution (maybe RecyclerView isn't the best direction), if it exists.
There's a design support library from Google.
Try this website:
http://hmkcode.com/material-design-app-android-design-support-library-appcompat/

Width of buttons wont change even if i set them to any kind of dp, but height for some reason works

I think it might have something to do with tablelayout, but there are 2 buttons in the layout and neither one of them I can change the width of, they fill up the screen but one of them is really small, the other takes up about 80% of the screens width. I've tried padding, layout_width, width, fill parent and changing other things but nothing works.
I can freely change the height but the width is uncontrollable, and the handles on the buttons don't resize it either.
this is what it looks like
http://postimg.org/image/b1f77b44v/
<TextView
android:id="#+id/lblName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textColor="#color/field_title" />
<EditText
android:id="#+id/editName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
android:textColor="#color/field" >
<requestFocus android:layout_width="match_parent" />
</EditText>
<TextView
android:id="#+id/lblDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/description"
android:textColor="#color/field_title" />
<EditText
android:id="#+id/editDesc"
android:layout_width="match_parent"
android:layout_height="80dp"
android:inputType="textMultiLine"
android:maxWidth="180dp"
android:padding="3dp"
android:singleLine="false"
android:textColor="#color/field" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="50dp"
android:layout_height="500dp" >
<TextView
android:id="#+id/lblStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/status"
android:textColor="#color/field_title" />
<Button
android:id="#+id/StatusChangeButton"
android:layout_width="30dp"
android:layout_height="fill_parent"
android:background="#drawable/ButtonTest"
android:maxWidth="50dip"
android:text="#string/change"
android:textColor="#color/button_text"
android:width="40dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="50dp"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/lblduedate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/due_date"
android:textColor="#color/field_title" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:baselineAligned="true" >
<Button
android:id="#+id/btnCancel"
android:layout_width="fill_content"
android:layout_height="wrap_content"
android:text="#string/cancel"
android:textColor="#color/button_text" />
<Button
android:id="#+id/btnSave"
android:layout_width="60dp"
android:layout_height="50dp"
android:text="#string/save"
android:textColor="#color/button_text" />
</TableRow>
</TableLayout>
</LinearLayout>
You can use weight to specify the in ratio the portion of each button would take from the whole table raw width.
But I am not sure why you choose to use Table. the better approach is to use linear layouts.
<TableRow
android:id="#+id/tableRow5"
android:baselineAligned="true" >
<Button
android:id="#+id/btnCancel"
android:layout_width="fill_content"
android:layout_height="wrap_content"
android:text="#string/cancel"
android:textColor="#color/button_text"
android:layout_weight="1"/>
<Button
android:id="#+id/btnSave"
android:layout_width="fill_content"
android:layout_height="wrap_content"
android:text="#string/save"
android:textColor="#color/button_text"
android:layout_weight="1"/>
</TableRow>
try this instead of tableRow
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:id="#+id/l1" >
<Button
android:id="#+id/btnCancel"
android:layout_width="fill_content"
android:layout_height="wrap_content"
android:text="#string/cancel"
android:layout_heigh="1"<!---add this-->
android:textColor="#color/button_text" />
<Button
android:id="#+id/btnSave"
android:text="#string/save"
android:layout_heigh="1"<!---add this-->
android:textColor="#color/button_text" />
</LinearLayout>

Categories