how to properly set contents of mobile screen; divide screen into multiple views
up vote
0
down vote
favorite
I have 1 toolbar, list view in 1 activity. 1 button in fragment. But toolbar overlaps the starting area of list. Button is displayed in the middle of bottom screen. But list item shows on the horizontal sides of button, which I do n ot want. My code is as belows -
public class RoomShareFragment extends Fragment {
private Button button;
View retView;
public RoomShareFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
retView = inflater.inflate(R.layout.fragment_room_share, container, false);
button = retView.findViewById(R.id.button1);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity)retView.getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
button.setX(width/2-100);
button.setY(height-450);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});
return retView;
}
}
public class RoomShare extends AppCompatActivity {
DB2CursorAdapter DBAdapter;
MessDatabase mdb;
Cursor cursor;
ListView listview;
String s = "hi";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room_share);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String selectQuery = "SELECT * FROM " + TempDataFromDB.TABLE_NAME /*+ " ORDER BY " + TempDataFromDB.COLUMN_MESS_NAME + " DESC"*/;
this.deleteDatabase("ShareRoom_db");
mdb = new MessDatabase(this);
SQLiteDatabase db = mdb.getWritableDatabase();
cursor = db.rawQuery(selectQuery,null);
DBAdapter = new DB2CursorAdapter(this, cursor, 0);
listview = (ListView) findViewById(R.id.listview);
listview.setAdapter(DBAdapter);
DBAdapter.notifyDataSetChanged();
}
fragment_room_share.xml
<android.support.constraint.ConstraintLayout 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=".RoomShareFragment"
tools:showIn="@layout/activity_room_share">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#ffffff"
android:background="@drawable/draw"
android:text="Buttons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RoomShare!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
activity_room_share.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".RoomShare">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView android:id="@+id/listview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="5"/>
<include layout="@layout/content_room_share" />
</android.support.design.widget.CoordinatorLayout>
android view fragment
add a comment |
up vote
0
down vote
favorite
I have 1 toolbar, list view in 1 activity. 1 button in fragment. But toolbar overlaps the starting area of list. Button is displayed in the middle of bottom screen. But list item shows on the horizontal sides of button, which I do n ot want. My code is as belows -
public class RoomShareFragment extends Fragment {
private Button button;
View retView;
public RoomShareFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
retView = inflater.inflate(R.layout.fragment_room_share, container, false);
button = retView.findViewById(R.id.button1);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity)retView.getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
button.setX(width/2-100);
button.setY(height-450);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});
return retView;
}
}
public class RoomShare extends AppCompatActivity {
DB2CursorAdapter DBAdapter;
MessDatabase mdb;
Cursor cursor;
ListView listview;
String s = "hi";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room_share);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String selectQuery = "SELECT * FROM " + TempDataFromDB.TABLE_NAME /*+ " ORDER BY " + TempDataFromDB.COLUMN_MESS_NAME + " DESC"*/;
this.deleteDatabase("ShareRoom_db");
mdb = new MessDatabase(this);
SQLiteDatabase db = mdb.getWritableDatabase();
cursor = db.rawQuery(selectQuery,null);
DBAdapter = new DB2CursorAdapter(this, cursor, 0);
listview = (ListView) findViewById(R.id.listview);
listview.setAdapter(DBAdapter);
DBAdapter.notifyDataSetChanged();
}
fragment_room_share.xml
<android.support.constraint.ConstraintLayout 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=".RoomShareFragment"
tools:showIn="@layout/activity_room_share">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#ffffff"
android:background="@drawable/draw"
android:text="Buttons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RoomShare!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
activity_room_share.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".RoomShare">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView android:id="@+id/listview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="5"/>
<include layout="@layout/content_room_share" />
</android.support.design.widget.CoordinatorLayout>
android view fragment
please include your xml code as well,that will help a lot
– Ajay Chauhan
Nov 9 at 13:57
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have 1 toolbar, list view in 1 activity. 1 button in fragment. But toolbar overlaps the starting area of list. Button is displayed in the middle of bottom screen. But list item shows on the horizontal sides of button, which I do n ot want. My code is as belows -
public class RoomShareFragment extends Fragment {
private Button button;
View retView;
public RoomShareFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
retView = inflater.inflate(R.layout.fragment_room_share, container, false);
button = retView.findViewById(R.id.button1);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity)retView.getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
button.setX(width/2-100);
button.setY(height-450);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});
return retView;
}
}
public class RoomShare extends AppCompatActivity {
DB2CursorAdapter DBAdapter;
MessDatabase mdb;
Cursor cursor;
ListView listview;
String s = "hi";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room_share);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String selectQuery = "SELECT * FROM " + TempDataFromDB.TABLE_NAME /*+ " ORDER BY " + TempDataFromDB.COLUMN_MESS_NAME + " DESC"*/;
this.deleteDatabase("ShareRoom_db");
mdb = new MessDatabase(this);
SQLiteDatabase db = mdb.getWritableDatabase();
cursor = db.rawQuery(selectQuery,null);
DBAdapter = new DB2CursorAdapter(this, cursor, 0);
listview = (ListView) findViewById(R.id.listview);
listview.setAdapter(DBAdapter);
DBAdapter.notifyDataSetChanged();
}
fragment_room_share.xml
<android.support.constraint.ConstraintLayout 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=".RoomShareFragment"
tools:showIn="@layout/activity_room_share">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#ffffff"
android:background="@drawable/draw"
android:text="Buttons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RoomShare!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
activity_room_share.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".RoomShare">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView android:id="@+id/listview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="5"/>
<include layout="@layout/content_room_share" />
</android.support.design.widget.CoordinatorLayout>
android view fragment
I have 1 toolbar, list view in 1 activity. 1 button in fragment. But toolbar overlaps the starting area of list. Button is displayed in the middle of bottom screen. But list item shows on the horizontal sides of button, which I do n ot want. My code is as belows -
public class RoomShareFragment extends Fragment {
private Button button;
View retView;
public RoomShareFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
retView = inflater.inflate(R.layout.fragment_room_share, container, false);
button = retView.findViewById(R.id.button1);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity)retView.getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
button.setX(width/2-100);
button.setY(height-450);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});
return retView;
}
}
public class RoomShare extends AppCompatActivity {
DB2CursorAdapter DBAdapter;
MessDatabase mdb;
Cursor cursor;
ListView listview;
String s = "hi";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room_share);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String selectQuery = "SELECT * FROM " + TempDataFromDB.TABLE_NAME /*+ " ORDER BY " + TempDataFromDB.COLUMN_MESS_NAME + " DESC"*/;
this.deleteDatabase("ShareRoom_db");
mdb = new MessDatabase(this);
SQLiteDatabase db = mdb.getWritableDatabase();
cursor = db.rawQuery(selectQuery,null);
DBAdapter = new DB2CursorAdapter(this, cursor, 0);
listview = (ListView) findViewById(R.id.listview);
listview.setAdapter(DBAdapter);
DBAdapter.notifyDataSetChanged();
}
fragment_room_share.xml
<android.support.constraint.ConstraintLayout 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=".RoomShareFragment"
tools:showIn="@layout/activity_room_share">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#ffffff"
android:background="@drawable/draw"
android:text="Buttons" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RoomShare!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
activity_room_share.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".RoomShare">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView android:id="@+id/listview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="5"/>
<include layout="@layout/content_room_share" />
</android.support.design.widget.CoordinatorLayout>
android view fragment
android view fragment
edited Nov 9 at 14:49
asked Nov 9 at 11:06
user1434287
5210
5210
please include your xml code as well,that will help a lot
– Ajay Chauhan
Nov 9 at 13:57
add a comment |
please include your xml code as well,that will help a lot
– Ajay Chauhan
Nov 9 at 13:57
please include your xml code as well,that will help a lot
– Ajay Chauhan
Nov 9 at 13:57
please include your xml code as well,that will help a lot
– Ajay Chauhan
Nov 9 at 13:57
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224547%2fhow-to-properly-set-contents-of-mobile-screen-divide-screen-into-multiple-views%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
please include your xml code as well,that will help a lot
– Ajay Chauhan
Nov 9 at 13:57