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>









share|improve this question
























  • please include your xml code as well,that will help a lot
    – Ajay Chauhan
    Nov 9 at 13:57















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>









share|improve this question
























  • please include your xml code as well,that will help a lot
    – Ajay Chauhan
    Nov 9 at 13:57













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>









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()