Android progress bar not showing up in custom view - android

I'm trying to create a custom view that contains a button and a progressbar. This is the XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/selector_button_primary"
android:padding="#dimen/size_s"
android:text=""
android:textColor="#android:color/white"
android:textSize="#dimen/size_m" />
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center"
android:indeterminate="true"
android:indeterminateTint="#android:color/white"
android:indeterminateTintMode="src_atop"
android:padding="#dimen/size_xxs"
android:elevation="2dp"
android:visibility="gone"/>
</FrameLayout>
And I created a custom view with
public class ProgressButton extends FrameLayout {
private boolean isLoading = false;
ProgressBar progressBar;
Button button;
String text;
#Override
public void setOnClickListener(#Nullable OnClickListener l) {
super.setOnClickListener(l);
button.setOnClickListener(l);
}
public void setText(String text){
this.text = text;
button.setText(text);
}
public boolean isLoading() {
return isLoading;
}
public void setLoading(boolean loading) {
isLoading = loading;
if (isLoading) {
button.setText("");
button.setClickable(false);
progressBar.setVisibility(VISIBLE);
} else {
progressBar.setVisibility(GONE);
button.setText(text);
button.setClickable(true);
}
System.out.println("Progressbutton: IsLoading "+isLoading);
}
public ProgressButton(Context context) {
super(context);
initView();
}
public ProgressButton(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}
public ProgressButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}
private void initView() {
System.out.println("initview");
View inflated = inflate(getContext(), R.layout.loader_button_primary, this);
progressBar = inflated.findViewById(R.id.progressbar);
button = inflated.findViewById(R.id.button);
}
}
and use it like this
val bt_sign_in = findViewById(R.id.bt_startup_sign_in) as ProgressButton
bt_sign_in.setText("Log in")
bt_sign_in.setOnClickListener{
bt_sign_in.setLoading(!bt_sign_in.isLoading)
}
And now something very weird happens:
- The text is appearing and dissapearing as how I expect.
- The progressbar is never showing up
- but when I set android:visibility="visible" in the XML file, I do see the progressbar as I expect. But after clicking it stays invisible.
Why does it stay hidden programmatically?

You have two clicklistener and with your logic
bt_sign_in.setLoading(!bt_sign_in.isLoading)
your toggle the progressbar and text.
Is VISIBLE and GONE imported correctly? From View Package?

Related

Custom compound view extended from RelativeLayout. Incorrect positioning of child views

I want to make widget which includes EditText and TextView and looks like this:
.
To achieve this I've created RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<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="48dp">
<EditText
android:id="#+id/editTextHint"
style="#style/CustomEditTextTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="14dp"
android:textColor="#color/textColor"
android:textSize="16sp"
android:hint="To my first character"
tools:text="Тип клиента">
</EditText>
<TextView
android:id="#+id/textViewContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editTextHint"
android:layout_alignParentEnd="true"
android:layout_above="#id/editTextHint"
tools:text="Продавец"
android:fontFamily="#font/proxima_nova_regular"
android:textSize="16sp"
android:layout_marginEnd="4dp"
android:textColor="#color/colorPrimary"/>
</RelativeLayout>
The above RelativeLayout works great and it looks as planned. To make Compound view I've removed </RelativeLayout> tag and wrapped it into the </merge> (I don't apply code as it's identical except of RelativeLayout tag)
To work with view I've written MyCustomEditText class which extendes RelativeLayout
public class CustomEditText extends RelativeLayout {
private EditText editTextHint;
private TextView textViewEntry;
private String hintText;
private String inputText;
private String starterText;
private OnCustomEditTextListener listener;
public String getHintText() {
return hintText;
}
public String getInputText() {
return inputText;
}
public void setHintText(String hintText) {
editTextHint.setText(hintText);
}
public void setInputText(String inputText) {
textViewEntry.setText(inputText);
}
public CustomEditText(Context context) {
super(context);
initializeViews(context);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray;
typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomEditText);
hintText = typedArray.getString(R.styleable.CustomEditText_hintText);
inputText = typedArray.getString(R.styleable.CustomEditText_inputText);
starterText = typedArray.getString(R.styleable.CustomEditText_starterText);
typedArray.recycle();
initializeViews(context);
}
private void initializeViews(Context context) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_edit_text, this);
setMinimumHeight(48);
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
editTextHint = findViewById(R.id.editTextHint);
textViewEntry = findViewById(R.id.textViewContent);
bindDataToChildViews();
editTextHint.setOnClickListener(v -> listener.onClick());
}
private void bindDataToChildViews() {
editTextHint.setText(hintText);
if ((inputText == null)||(inputText.isEmpty())) {
textViewEntry.setText(starterText);
} else {
textViewEntry.setText(inputText);
}
}
public void setHintClickListener(OnCustomEditTextListener listener) {
this.listener = listener;
}
public interface OnCustomEditTextListener {
void onClick();
}
}
I'm trying tu use this view in other layouts but the positioning of text view is ugly:
I thought that extending view from RelativeLayout would be enough for correct positioning. So I need your help to define where I'me getting wrong. How to position elements correctly?
P.S. The replacement of RelativeLayout for merge tag was made to optimize drawing of views and avoiding unnecessary nesting layouts
First of all you dont need to have
android:layout_above="#id/editTextHint"
And add
android:layout_gravity="center_vertical"
to editTextHint and textViewContent
Also possibly you should remove
android:layout_marginEnd="4dp"
or change a bit it's value

Show loader on Spinner (Dropdown) when it is fetching data from web service

In the image above, I have shown that when the user touches the drop-down spinner it will call the web api for getting data for the spinner. Then, that moment, I want to show the loader only on the spinner view on the left or right somewhere on the view itself like in the image, rather than on whole screen when it is getting data from the web service dynamically and hide that progress bar later when web service completely hit at the end (Ignore that search bar in image).
Just create an custom adapter for your spinner. Follow the instructions found here How to create Spinner-list using CustomAdapter in android .
Put the loading view in the layout inflated in the getView method in the adapter, and manipulate it via a callback from your async task used for fetching the result.
In this i am showing loader on start button and hiding loader when stop button is pressed so you can use according to your need.So , for this i have made three class CustomSpinner,Spinner_Custom_adapter and Activity class for using it
In main layout file
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<www.your_packagename.com.spinnerwithloaderex.CustomSpinner
android:id="#+id/custm_spnr"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="#drawable/dropdown_create_sales"
android:paddingRight="15dp"
android:text="Hello World!" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<Button
android:id="#+id/start_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start" />
<Button
android:id="#+id/stop_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop" />
</LinearLayout>
</LinearLayout>
CustomSpinner class
public class CustomSpinner extends android.support.v7.widget.AppCompatSpinner {
private Spinner_Custom_adapter spinner_custom_adapter;
public CustomSpinner(Context context) {
super(context);
}
public CustomSpinner(Context context, int mode) {
super(context, mode);
}
public CustomSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) {
super(context, attrs, defStyleAttr, mode);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) {
super(context, attrs, defStyleAttr, mode, popupTheme);
}
public void setItems(Activity activity, ArrayList<String> spnr_Arr) {
spinner_custom_adapter = new Spinner_Custom_adapter(activity, spnr_Arr);
setAdapter(spinner_custom_adapter);
}
public Spinner_Custom_adapter getSpinner_custom_adapter() {
return spinner_custom_adapter;
}
public void showLoader() {
setEnabled(false);
spinner_custom_adapter.showLoader(true, true);
}
public void dismissLoader() {
setEnabled(true);
spinner_custom_adapter.showLoader(false, true);
}
}
Custom_Adapter class
public class Spinner_Custom_adapter<T> extends ArrayAdapter<T> {
private LayoutInflater flater;
private ProgressBar spinner_progress;
private TextView txtTitle;
private Boolean showOrNot = false;
Spinner_Custom_adapter(Activity context, ArrayList<T> list) {
super(context, R.layout.loader_spinner_lt, R.id.title, list);
flater = context.getLayoutInflater();
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = flater.inflate(R.layout.loader_spinner_lt, parent, false);
}
Object object = getItem(position);
String rowItem = null;
if (object instanceof String) {
rowItem = (String) object;
}
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
txtTitle.setText(rowItem);
ProgressBar spinner_progress = (ProgressBar) convertView.findViewById(R.id.spinner_progress);
this.txtTitle = txtTitle;
this.spinner_progress = spinner_progress;
showLoader(showOrNot, false);
return convertView;
}
void showLoader(Boolean showOrNot, boolean notifyListOrNot) {
if (txtTitle != null && spinner_progress != null) {
this.showOrNot = showOrNot;
spinner_progress.setVisibility(showOrNot ? View.VISIBLE : View.GONE);
if (notifyListOrNot) {
notifyDataSetChanged();
}
}
}
}
Spinner single view layout xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/spinner_progress"
android:ellipsize="end"
android:singleLine="true"
android:text="Strawberry"
android:textColor="#CC0033"
android:textSize="16dp" />
<ProgressBar
android:id="#+id/spinner_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="gone" />
</RelativeLayout>
and for using it
custm_spnr = (CustomSpinner) findViewById(R.id.custm_spnr);
ArrayList<String> items = new ArrayList<>();
items.add("Abcdefg");
items.add("hijklm");
items.add("nopqr");
items.add("stu");
items.add("vwxyza1b1c1");
items.add("d1e1f11g1h1");
custm_spnr.setItems(MainActivity.this, items);
findViewById(R.id.start_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
custm_spnr.showLoader();
}
});
findViewById(R.id.stop_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
custm_spnr.dismissLoader();
}
});

Add onClickListener on constraint layout inside custom layout with binding

I am trying to add an onClickListener on a constraint layout that I have it embedded in my layout with no luck.
I have a class and a layout called view_button that contains these elements:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<android.support.constraint.ConstraintLayout
android:id="#+id/main_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_button"
android:clickable="true"
android:focusable="true">
<ImageView
android:id="#+id/icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="#drawable/ic_add_24_vector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="5dip"
android:fontFamily="#font/lato_regular"
android:gravity="center_vertical"
android:text="START"
android:textColor="#color/color_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
And my corresponding Java class
public class SprintLaunchButton extends ConstraintLayout {
private TextView mTextView;
private ImageView mIconImageView;
protected CharSequence attr_text = null;
protected Drawable attr_image_drawable = null;
public SprintLaunchButton(Context context) {
super(context);
inflateView(context);
init(null);
setView(context);
}
public SprintLaunchButton(Context context, AttributeSet attrs) {
super(context, attrs);
inflateView(context);
init(attrs);
setView(context);
}
public SprintLaunchButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
inflateView(context);
init(attrs);
setView(context);
}
private void inflateView(Context context) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.view_sprint_button, this, true);
mTextView = findViewById(R.id.text);
mIconImageView = findViewById(R.id.icon);
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
setLayoutParams(params);
}
private void init(AttributeSet attrs) {
consumeAttrs(getContext().obtainStyledAttributes(attrs, R.styleable.SprintLaunchButtonLayout));
}
public TextView getTextView() {
return mTextView;
}
private void consumeAttrs(TypedArray styledAttrs) {
if (styledAttrs == null) {
return;
}
attr_text = styledAttrs.getString(R.styleable.SprintLaunchButtonLayout_buttonText);
attr_image_drawable = styledAttrs.getDrawable(R.styleable.SprintLaunchButtonLayout_iconImage);
styledAttrs.recycle();
}
public void setIconImage(#DrawableRes int id) {
try {
if (mIconImageView != null) {
mIconImageView.setImageDrawable(getContext().getDrawable(id));
}
} catch (Resources.NotFoundException e) {
}
}
public void setButtonText(#StringRes int id) {
try {
if (mTextView != null) {
mTextView.setText(getContext().getString(id));
}
} catch (Resources.NotFoundException e) {
}
}
protected void setView(Context context) {
if (attr_text == null) {
mTextView.setText("");
} else {
mTextView.setText(attr_text);
}
if (attr_image_drawable == null) {
mIconImageView.setImageDrawable(null);
} else {
mIconImageView.setImageDrawable(attr_image_drawable);
}
}
}
When I add my custom layout to my application using my Java class as follows:
<com.netexlearning.play.view.SprintLaunchButton
android:id="#+id/main_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd=" app:layout_constraintBottom_toBottomOf="#+id/thumbnail"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/thumbnail">
</com.netexlearning.play.view.SprintLaunchButton>
I am able to use and see this new created layout inside the main layout of my application, but the problem stars when trying to add an onClickClickListener.
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_detail_sprint, dataBindingComponent);
mViewModel = ViewModelProviders.of(this, viewModelFactory)
.get(SprintDetailViewModel.class);
mBinding.mainAction.setOnClickListener(view -> Timber.e("test");
}
This listener is never called, even if I add the onClickListener on the TextView itself..
I have to change my custom layout and remove the TextView an ImageView an add a Button, then in my MainActivity class add the onClickListener to be able to fire the action like so:
mBinding.mainAction.getButton.setOnClickListener(view -> Timber.e("test");
My question is.. is there a way to fire an onClickListener on a custom constraint layout?. Even if I add a method to retrieve my textView or imageView the onClickListener doesn't work.
Thank you so much, if you have any question do not hesitate to ask me.
SprintLaunchButton must implement View.OnClickListener interface . And I believe you must do it from the class you created your View Variables

Android FrameLayouts in GridLayout not showing

I'm trying to make something like the following screenshot (it's from an assignment from school):
As mentioned in the assignment, I have an Activity PlayActivity:
public class PlayActivity extends ActionBarActivity {
#Bind(R.id.activity_play_textView_score)
TextView txtScore;
#Bind(R.id.activity_play_board)
Board board;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
ButterKnife.bind(this);
}
}
The xml-layout for this activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/activity_play_textView_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/activity_play_textView_score_placeholder"/>
<com.charlotteerpels.game2048.Board
android:id="#+id/activity_play_board"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
We also had to make a class Card, which is an extension of a FrameLayout:
public class Card extends FrameLayout {
#Bind(R.id.card_frame_layout_textView)
TextView txtNumber;
private int number;
public void setTxtNumber(TextView txtNumber) {
this.txtNumber = txtNumber;
}
public TextView getTxtNumber() {
return this.txtNumber;
}
public void setNumber(int number) {
this.number = number;
}
public int getNumber() {
return this.number;
}
public Card(Context context, AttributeSet attributeSet, int defaultStyle) {
super(context, attributeSet, defaultStyle);
inflateLayout();
ButterKnife.bind(this);
}
public Card(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
inflateLayout();
ButterKnife.bind(this);
}
public Card(Context context) {
super(context);
inflateLayout();
ButterKnife.bind(this);
}
private void inflateLayout() {
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)getContext().getSystemService(infService);
li.inflate(R.layout.card_frame_layout, this, true);
}
}
The xml-layout for this class:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/card_frame_layout_background"
android:layout_margin="4dp">
<TextView
android:id="#+id/card_frame_layout_textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/card_frame_layout_textView_placeholder"
android:textSize="40sp"
android:layout_gravity="center"/>
</FrameLayout>
At least we had to make a class Board, which is an extension of a GridLayout:
public class Board extends GridLayout {
Card[][] cardBoard;
public Board(Context context, AttributeSet attributeSet, int defaultStyle) {
super(context, attributeSet, defaultStyle);
initBoard(context);
}
public Board(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
initBoard(context);
}
public Board(Context context) {
super(context);
initBoard(context);
}
public void initBoard(Context context) {
//Set the settings for the GridLayout (the grid is the board)
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)getContext().getSystemService(infService);
li.inflate(R.layout.board_grid_layout, this, true);
//Initialize the cardBoard[][] and populate it
cardBoard = new Card[4][4];
for(int rij=0; rij<4; rij++) {
for(int kolom=0; kolom<4; kolom++) {
cardBoard[rij][kolom] = new Card(getContext());
}
}
int cardMeasure = getCardMeasure(context);
addCardBoardToGridLayout(cardMeasure);
}
private void addCardBoardToGridLayout(int cardMeasure) {
for(int rij=0; rij<4; rij++) {
for(int kolom=0; kolom<4; kolom++) {
Card card = cardBoard[rij][kolom];
addView(card, cardMeasure, cardMeasure);
}
}
}
private int getCardMeasure(Context context) {
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;
return screenWidth/4;
}
}
The xml-layout for the Board:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/board_grid_layout_background"
android:columnCount="4"
android:rowCount="4">
</GridLayout>
But all I'm getting is this:
I'm also using Butterknife (website: http://jakewharton.github.io/butterknife/)
for binding resources, but mostly to bind views and elements from the xml-layouts.
Can anybody help me?
Found what was wrong!
So in the xml-layout from Card, I changed the layout_width and layout_height from the TextView:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/card_frame_layout_background"
android:layout_margin="4dp">
<TextView
android:id="#+id/card_frame_layout_textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/card_frame_layout_textView_placeholder"
android:textSize="40sp"
android:layout_gravity="center"/>
</FrameLayout>
The "addCardBoardToGridLayout(int cardMeasure)" changed to the following:
private void addCardBoardToGridLayout(int cardMeasure) {
setRowCount(4);
setColumnCount(4);
removeAllViews();
for(int rij=0; rij<4; rij++) {
for(int kolom=0; kolom<4; kolom++) {
Card card = cardBoard[rij][kolom];
addView(card, cardMeasure, cardMeasure);
}
}
}
Now it looks like this (and it's exactly like I wanted it!):

How to set WearableListView item height

I make WearableListView list. Problem is that setting android:layout_height="20dp" doesn't help
How to set height in this case? In Android Wear sample projects Notifications and Timer they also just set atribute android:layout_height="80dp". But I tried to set in the projects android:layout_height="20dp" but it didn't help! (below is my project source code):
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="20dp"
android:gravity="center_vertical" >
<TextView
android:id="#+id/text_hole"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:textSize="#dimen/list_item_text_size" />
</base.mobitee.com.mobiteewatch.adapter.HolesListItemLayout>
HolesListItemLayout.java:
public class HolesListItemLayout extends LinearLayout
implements WearableListView.OnCenterProximityListener {
private TextView mName;
private final int mFadedTextColor;
private final int mChosenTextColor;
public HolesListItemLayout(Context context) {
this(context, null);
}
public HolesListItemLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HolesListItemLayout(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
mFadedTextColor = getResources().getColor(R.color.grey);
mChosenTextColor = getResources().getColor(R.color.black);
}
// Get references to the icon and text in the item layout definition
#Override
protected void onFinishInflate() {
super.onFinishInflate();
mName = (TextView) findViewById(R.id.text_hole);
}
#Override
public void onCenterPosition(boolean animate) {
mName.setTextSize(18);
mName.setTextColor(mChosenTextColor);
}
#Override
public void onNonCenterPosition(boolean animate) {
mName.setTextColor(mFadedTextColor);
mName.setTextSize(14);
}
}
HolesListAdapter.java:
public class HolesListAdapter extends WearableListView.Adapter {
private final Context mContext;
private final LayoutInflater mInflater;
public HolesListAdapter(Context context) {
this.mContext = context;
mInflater = LayoutInflater.from(context);
}
#Override
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new WearableListView.ViewHolder(
mInflater.inflate(R.layout.list_item_hole, null));
}
#Override
public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
TextView text = (TextView) holder.itemView.findViewById(R.id.text_hole);
text.setText(mContext.getString(R.string.hole_list_item) + " " + (position + 1));
text.setTextColor(mContext.getResources().getColor(android.R.color.black));
holder.itemView.setTag(position);
}
#Override
public int getItemCount() {
return Preferences.HOLES;
}
}
The WearableListView is hard-coded to only display three items at a time - it measures the item height by dividing the list view's height by three ... so there isn't a practical way of doing what you want.
I suggest making the text font larger ...
I've got idea. Insert list into FrameLayout container. And by changing height of container list item height is changed. Result:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_centerInParent="true">
<android.support.wearable.view.WearableListView
android:id="#+id/wearable_list_game_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dividerHeight="0dp"
android:scrollbars="none"/>
</FrameLayout>
</RelativeLayout>
Add one LinearLayout inside and set
android:layout_height="50dp"
android:layout_margin="5dp"

Categories

Resources