Whenever we use seekbar on cardview how to stop seekbar to get into focus on when cardview have clickable true attribute - android-layout

When click on cardview, seek bar is get into focus, when cardview have clickable "true" attribute.
<androidx.cardview.widget.CardView
android:id="#+id/cardview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="12dp"
android:clickable="true"
android:visibility="visible"
app:cardBackgroundColor="#color/darkGray"
tools:ignore="MissingConstraints">
<SeekBar
android:id="#+id/seekbar"
android:layout_width="0dp"
android:layout_height="20dp"
android:max="360"
android:progressBackgroundTint="#color/white"
android:progressTint="#color/white" />
</androidx.cardview.widget.CardView>
When I use clickable true property in cardview , after click anywhere on cardview seekbar is get in foucus. But when I remove that property map drags and moves because cardview is on MapView.
Cardview is on Mapview so mapview should not be clicked when I click on cardview and seekbar should not get in focus.

Related

Align the text to center in ListView

I've created a stopwatch app when the user clicks the Lap button just gives the current time the timer is at. My problem is text in ListView displays at the left corner. I'm finding it impossible to center the text in my listview. Here I attached my XML and Java code.
activity_main.xml
<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"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="100dp"
android:text="format"
android:textSize="40dp"
android:textStyle="bold" />
<Button
android:id="#+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="110dp"
android:text="Start" />
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#id/start"
android:text="Reset" />
<ListView
android:id="#+id/listview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/start"
android:layout_marginLeft="50dp"
android:layout_marginTop="9dp"
android:layout_marginRight="50dp"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />
</RelativeLayout>
MainActivity.java:
public class MainActivity extends AppCompatActivity
{
TextView time;
Button reset, start;
ListView listView;
long startTime, TimeBuff, millisecondsTime, UpdateTime = 0L;
int seconds, milliseconds, minutes;
Handler handler;
List<String> ListElementsArrayList;
ArrayAdapter<String> adapter;
String[] ListElements = new String[]{};///creating arrays of string type
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
time = (TextView) findViewById(R.id.textView);
start = (Button) findViewById(R.id.start);
reset = (Button) findViewById(R.id.reset);
listView = (ListView) findViewById(R.id.listview1);
handler = new Handler();
//Getting the list of array
ListElementsArrayList = new ArrayList<String>(Arrays.asList(ListElements));
adapter = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_1,
ListElementsArrayList);
listView.setAdapter(adapter);
}
}
To do it You have to create a layout in Your res/layout folder. With name e.g. list_item_layout.xml. In this layout add this:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20sp" />
In this file, You can make custom TextView which You want to display (change font, size etc.). To center text use android:gravity="center"
Next, when You create an ArrayAdapter, use this layout:
adapter = new ArrayAdapter<String>(
MainActivity.this,
R.layout.list_item_layout, // here You use created layout
ListElementsArrayList
);
Result:

How I can show the navigational bar icon on the left of my customized action bar

I have customized my action bar with the following:
Title at the center
Title with customized font from asset
Title does not have the application icon
What I want is the navigational drawer icon on left.
Right now you can see it is on the left of the title My App. I want to have my application title on center only without the navigational drawer icon.
I tried with ImageView inside my customized action bar layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv_nav_drawr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left"
android:src="#drawable/ic_navbar_drawer" />
<TextView
android:id="#+id/apptitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical"
android:text="#string/app_name" />
</RelativeLayout>
my activity code snippet for the action bar customization is:
private void actionBarCustomizations(){
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
//getActionBar().setDisplayShowTitleEnabled(true);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.app_action_bar, null);
TextView actionBarTitleTextView = (TextView)v.findViewById(R.id.apptitle);
Typeface neoTechMedium =
Typeface.createFromAsset(getAssets(), "fonts/NeoTech-Bold.ttf");
actionBarTitleTextView.setTypeface(neoTechMedium);
ActionBar.LayoutParams params = new
ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
getActionBar().setCustomView(v, params);
}
Any one can help me on this please?
HI Remove layout_gravity, and gravity from Image View.
Just Use
android:layout_alignParentLeft="true"
It's in ImageView property Ok...

Linear layout clickable error

In my Andoid app. I have a clickable linear layout that I've generated programmaticly, and I want it to turn green when it is pressed to indicate that it is clickable, like a button would. How would I go about doing this?
This is my code i implemented in my Header layout.
<LinearLayout
android:id="#+id/back_lay"
android:layout_width="46dp"
android:layout_height="46dp"
android:layout_marginLeft="10dp"
android:background="#android:color/transparent"
android:gravity="center_vertical|center_horizontal" >
<Button
android:id="#+id/ib_back_music"
android:layout_width="30dp"
android:layout_height="32dp"
android:layout_marginLeft="5dp"
android:background="#drawable/back_btn_sel"
android:clickable="true"
android:gravity="center_vertical|center_horizontal|center" />
</LinearLayout>
private LinearLayout lLinearLayout;
//OnCreate
lLinearLayout = (LinearLayout) findViewById(R.id.back_lay);
lLinearLayout.setOnClickListener(new
{
#Override
public void onClick(View v)
{
lLinearLayout.setBackgroundColor(Color.BLACK);
}
});

Android - ScrollView like foursquare with maps + list

This is the Android equivalent of this iOS question.
Trying to create a view that contains a MapView at about 20% of the screen (under an ActionBar...) and the rest of the screen is a ScrollView that when scrolling down, overlaps on top of the MapView and hides it. In short like FourSquare's Android app.
Any ideas?
I've made an implementation based on AndroidSlidingUpPanel (many thanks to this project).
Details http://android.amberfog.com/?p=915
Source code with example: https://github.com/dlukashev/AndroidSlidingUpPanel-foursquare-map-demo
LAST UPDATE
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map_fragment"
android:name="com.myapp.MapFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent" />
<fragment
android:id="#id/list_fragment"
android:name="com.myapp.ListFragment"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
Then I add an invisible header to the list like so:
#Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.listview, container, false);
SwipeListView listView = (SwipeListView) view.findViewById(R.id.venue_list);
// An invisible view added as a header to the list and clicking it leads to the mapfragment
TextView invisibleView = new TextView(inflater.getContext());
invisibleView.setBackgroundColor(Color.TRANSPARENT);
invisibleView.setHeight(300);
invisibleView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
listener.moveToMapFragment();
}
});
listView.addHeaderView(invisibleView);
This is hardly ideal, but it works. I hope it helps someone..
The easiest solution is to add a margin to your slider content (second parameter of the SlidingUpPanel) and then remove the fading background. All done from the XML.
You can just declare in your xml file a ScrollView that embeds a LinearLayout, that embeds a MapView :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
...... Your list and other stuff .......
</LinearLayout>
</LinearLayout>
</ScrollView>
Then you can set the size for each element by specifying the layout_weight attribute
EDIT
IvanDanDo, following our discussion I found this link that may do what you want (not sure though, I didn't try it) : Android: Have an arbitrary View slide under another View like the software keyboard does

Android - UI Disappear after startActivity

I'm starting an simple ACTION.VIEW activity to show up the web browser.
But when the user press the "back" key, it returns to my initial application. The application is working perfectly except that all the main UI elements have disappeared.
Anyone knows why ?
Here's how I start the web browser :
//Go to web page
ImageButton web = (ImageButton) _gears.findViewById(R.id.Web);
web.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
try
{
String url = "http://apps.toonboom.com/flip-boom-lite-ipad";
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(url);
i.setData(u);
_mainActivity.startActivity(i);
}
catch (ActivityNotFoundException e)
{
// Raise on activity not found
Toast.makeText(_mainActivity.getApplicationContext(), "Browser not found.", Toast.LENGTH_SHORT);
}
}
});
When coming back from that browser page, onStart() and onResume() are called normally. What I don't understand is that the back and home button lifecycle works perfectly. The user can manually go away of the app and come back without any UI problems. The problem only occurs when coming back from that startActivity() call ?
Also, I don't need to retain any specific UI values....I just want them to be present in the layout ;)
EDIT
I have a gles view that I use to draw and I think it display itself in front of the other UI elements....But I don't understand why if that is the case....
Here's a piece of the xml and the onCreate method :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/MainLayout">
<!-- This is a dummy layout so we can add our custom GlView dynamically to this relative position -->
<LinearLayout
android:id="#+id/SurfaceViewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<!-- This is a dummy layout so we can add the timeline dynamically to this relative position -->
<HorizontalScrollView
android:id="#+id/TlScroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="0dip"
android:padding="0dip"
android:scrollbars="none"
android:fillViewport="false"
android:scrollbarFadeDuration="0"
android:scrollbarDefaultDelayBeforeFade="0"
android:fadingEdgeLength="0dip"
android:scaleType="centerInside">
<!-- HorizontalScrollView can only host one direct child -->
<LinearLayout
android:id="#+id/TimelineContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_margin="0dip"
android:padding="0dip"
android:scaleType="centerInside"/>
</HorizontalScrollView >
<RelativeLayout
android:id="#+id/BottomTools"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/TlScroller" >
<ImageButton
android:id="#+id/PaletteBtn"
android:layout_width="30dip"
android:layout_height="30dip"
android:background="#android:color/transparent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dip"
android:layout_marginBottom="60dip"
android:src="#drawable/palette44x44"
android:scaleType="centerInside"/>
<RelativeLayout
android:id="#+id/PadLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:src="#drawable/pad_btn"
android:scaleType="centerInside">
<ImageButton
android:id="#+id/PadBtn"
android:layout_width="75dip"
android:layout_height="75dip"
android:background="#android:color/transparent"
android:layout_centerInParent="true"
android:src="#drawable/pad_btn"
android:scaleType="centerInside"/>
<TextView
android:id="#+id/FrameCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dip"
android:padding="0dip"
android:layout_centerInParent="true"
android:textColor="#000000"
android:text="#/x"/>
</RelativeLayout>
<ImageButton
android:id="#+id/PreviousBtn"
android:layout_width="40dip"
android:layout_height="40dip"
android:background="#android:color/transparent"
android:layout_toLeftOf="#+id/PadLayout"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dip"
android:src="#drawable/previous_btn"
android:scaleType="centerInside"
android:scaleHeight="30%"
android:scaleWidth="30%"/>
// Goes like that with other ImageButton till the end bracket
= = =
#Override protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
//Set the main layout element
setContentView(R.layout.ui);
// Then most buttons are created like this . . .
//Create the tools pop-up menu
ImageButton toolBtn = (ImageButton) this.findViewById(R.id.CurrentToolBtn);
_tools = new ToolsPopup(toolBtn);
}
When you launching a web browser it uses a lot of memory so android killing your app, when it is going back to activity it recreates it. So you should save your dynamically added views using onsaveinstancestate and onrestoreinstancestate.
onSaveInstanceState () and onRestoreInstanceState ()

Resources